Reputation: 10249
I am in need of writing a simple mod_rewrite rule, as follows:
something.php ==> somehting (just get rid of the .php)
something_else.php ==> something/else (replace _ with /)
So, for example it would be like this:
www.mysite.com/something.php (would be rewritten as) www.mysite.com/something
www.mysite.com/something_else.php (would be rewritten as) www.mysite.com/something/else
As I am not familiar with regular expressions, I thought it would be simpler to ask someone who can do this in 5s rather than spend days (weeks? :P) learning regular expressions and mod_rewrite.
Thanks :)
Upvotes: 0
Views: 197
Reputation: 784918
Try these rules in .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^([^_]+)_([^_]+)\.php/?$ /$1/$2 [R=301,L]
RewriteRule ^([^.]+)\.php/?$ /$1 [R=301,L]
This will do external redirect, in case you don't want that then remove R=301,
flag from above.
Upvotes: 2