Reputation: 309
I have got this code inside a file called .htaccess to remove the extensions in my urls. I have tried both putting the .htaccess in the root folder but also the folder where the script is located, neither works.. anyone know why?
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule (.+)\.php$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.php [L]
Upvotes: 1
Views: 139
Reputation: 2780
I wouldn't use this if i where you, you should create dynamic URL's instead.
The error however is that you have not opend the RewriteEngine yet. Your should add:
RewriteEngine On
So your final file should look like:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteRule (.+)\.php$ $1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ $1.php [L]
Upvotes: 1