-1

I have a website having pages like login.php, home.php, register.php. All the essential pages for website operation are in php, my website generates a url as - website.domain/username.html every time a user registers for his/her profile (for other operations).

I want to remove using this .html at end of the links and want to have link as- website.domain/username.

I am hosting my website on 000webhost and I am aware of .htaccess file but still I don't have enough knowledge to use htaccess, I tried htaccess method but it crashed the site.

halfer
  • 19,471
  • 17
  • 87
  • 173
  • 2
    Does this answer your question? [How to remove .html from URL?](https://stackoverflow.com/questions/5730092/how-to-remove-html-from-url) – Don't Panic Mar 16 '22 at 07:35

1 Answers1

0

Try this, it worked for me:

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /l

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R=302,L,NE]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.html -f [NC]
RewriteRule ^ %{REQUEST_URI}.html [L]
halfer
  • 19,471
  • 17
  • 87
  • 173
pk_
  • 104
  • 6
  • thanks sir , this is what i wanted , it worked flawlessly , acutually i am a high school student making this website i dont know that much about apache stuff , thanks again sir – Ashutosh_7i Mar 16 '22 at 12:40