Reputation: 6868
I have read more than 3 questions here in stackoverflow about this, but all of them has one of the below problems:
Let me boil it down for you guys: I need to type index.htm and apache redirects that to .php but in the address bar I still want to see .htm not .php
Any help or suggestion would be appreciated.
Upvotes: 0
Views: 250
Reputation: 28707
RewriteEngine on
RewriteRule ([^/]*)\.htm$ $1.php [PT]
Please review http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule for all of the available options, including other flags you may want to include - such as QSA
.
Note that the RewriteEngine on
line (as well as Options FollowSymLinks
- see the docs linked to above) is necessary if you don't already have it elsewhere. You may also need AllowOverride FileInfo
in your primary Apache configuration to enable the use of .htaccess
files.
Note that the PT
flag is not strictly necessary, as it is the default if Apache determines it can fulfill the request without a redirect.
Here is another result I just found from a Google Search that shows pretty much the same thing I'm describing here: http://corz.org/serv/tricks/htaccess2.php (specifically shows some rules around the .htm -> .php translation.)
Upvotes: 1
Reputation: 22412
Hi it's easily done: In your .htaccess you will have a redirect like this:
RewriteRule ^(.*).htm$ $1.php [QSA]
RewriteRule ^(.*).html$ $1.php [QSA]
Upvotes: 0