Reputation: 39
I wanted to hide the php extension so writed
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I want to force redirect www to non www so i writed the htaccess code
RewriteBase /
#Force non-www:
RewriteCond %{HTTP_HOST} www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It redirecting nicely www to non www version But Not Perfectly As, when i'm typing url www.something.com it is redirecting to something.com But when giving url www.something.com/test it is redirecting to something.com/test.php
and also when i'm typing url www.something.com/example?id=1 it is redirecting to something.com/example.php?id=1
How To do redirect like www.something.com/test to something.com/test and not to show php extension after redirect.
Upvotes: 1
Views: 63
Reputation: 522081
If your redirect rule comes after your .php rewrite rule, then your problem is that the rewritten URL is getting redirected. I.e.:
www.example.com/test
to www.example.com/test.php
.example.com/test.php
.Either move your redirect rule above the other rule, or stop processing of further rules by adding [L]
after RewriteRule ^(.*)$ $1.php
.
Upvotes: 1