Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache .htaccess to hide both .php and .html extentions

What lines should I add to remove both .html and .php extensions from my site?

I use this for just the .html part:

RewriteEngine on

RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]

but I need for both file type extensions to be hidden from the same domain.

like image 565
Blazer Avatar asked Oct 26 '25 01:10

Blazer


1 Answers

I know its late to answer but I giving it since it can be useful to someone :)

#Remove php extension
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.*)$ $1.php

#Remove html extension
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.html -f 
    RewriteRule ^(.*)$ $1.html

This will remove both php and html extension from your files and works perfectly.

like image 143
Atai Rabby Avatar answered Oct 29 '25 13:10

Atai Rabby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!