1

I have this .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.html

The problem is: Its just hidding .php Shouldn't it hide .php and .html?

andershagbard
  • 1,116
  • 2
  • 14
  • 38
Lucas Ferraz
  • 620
  • 1
  • 7
  • 12
  • Possible duplicate of [htacces to hide both php and html extentions](http://stackoverflow.com/questions/15591251/htacces-to-hide-both-php-and-html-extentions) – cnst Feb 02 '16 at 23:17

2 Answers2

1

Change your rules to:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

1./ your html files are still accessible because your second set of rule will never be used. Besides, your second line specifically tells the server to leave "real" files aside.

2./ You only need RewriteEngine On once .

3./ You should use the flags to tell your rewriting when to stop.

RewriteEngine On
# if the requested file does not exist
RewriteCond %{REQUEST_FILENAME} !-f
# if the requested folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# sends all urls except home to its corresponding php file
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php [R=301,L]

But if you want it to work for all file extensions, remove the first rule, leaving only.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z,0-9,A-Z,_-]+)$ ./$1.php [R=301,L]
pixeline
  • 17,669
  • 12
  • 84
  • 109
  • 1
    please be carefurl with the 301 redirect, this can cause major problems with SEO and is IMO not what is asked here – giorgio Dec 04 '13 at 15:18
  • it seems to me it makes sense, if you redirect via htaccess (not typically a file you'd change every day) that you'd want the SE to take your redirects as legit urls. – pixeline Dec 04 '13 at 15:22