How to remove .php or .html off of website url

Website URL

website down rn
(please specify the URL of the site on which you are experiencing the problem)

Error Message

no error message but how do i remove .php and .html off of my webpages of my website
(please share the FULL error message you see, if applicable)

Other Information

(other information and details relevant to your question)

you can add the following to your .htaccess file (or create one if you’ve not got one already)

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)$ $1.php [NC,L]

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.]+)$ $1.html [NC,L]

Hope that helps :slight_smile:

5 Likes

Something like this should work

Create a file named .htaccess in your /htdocs directory containing the following code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

This will allow you to remove the .php extension, change the rewrite rule in last line to $1.html if you wish to remove .html instead

4 Likes

Sorry I was slow at typing, @dan3008 's solution is better :+1:

2 Likes

its not working https://chatnow.42web.io/

Can you clarify what exactly is not work? Can you share an example URL that’s not working, and describe what you expect to see instead?

The home page of your website seems to work just fine from here.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.