1
votes

If a person visits: http://domain.com, I want to redirect him to http://www.domain.com and if a person visits: http://domain.com/remove.php, I would like to redirect him to http://www.domain.com/remove

So basically, I want to add a www in the beginning of the url if a subdomain is not being requested and I also want the user to be redirected to a URL without the PHP extension in case he tries to access one. I know, how to accept pages which don't have .php extension but now I'm looking to a code for all the above features along with a redirection code which will redirect the user to a non PHP extension page in case he tries to visit one with the PHP extension

So, if he visits, he reaches ...

1

1 Answers

3
votes
RewriteEngine On
# First force the www (ignoring case)
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301,QSA]

# And this rule rewrites the .php off the end.
RewriteRule ^/([A-Za-z0-9)\.php http://www.example.com/$1 [L,R,QSA]