views:

20

answers:

2

Given a set of URL as follows:

http://site.com/filename.html
http://site.com/filename.htm
http://site.com/filename.php
http://site.com/filename

Using the mod_rewrite module in .htaccess, how can I make it request the file at

http://site.com/filename.php

and show the URL

http://site.com/filename
+1  A: 
Lauri Lehtinen
http://site.com/filename.html, http://site.com/filename.htm gives me a 404 with that. http://site.com/filename appears as http://site.com/filename.php. Does not satisfy the constraints.
Havvy
+1  A: 

Try these rules:

# remove file name extension and redirect externally
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]+\.(html?|php)
RewriteRule ^([^.]+)\.(html?|php)$ /$1 [L,R=301]

# rewrite to PHP file internally
RewriteRule ^[^.]+$ $0.php [L]
Gumbo