[英]Simple rewrite rule for mod_rewrite
I am in need of writing a simple mod_rewrite rule, as follows:我需要写一个简单的 mod_rewrite 规则,如下:
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.由于我不熟悉正则表达式,我认为问一个可以在 5 秒内完成此任务的人,而不是花几天(几周?:P)学习正则表达式和 mod_rewrite 会更简单。
Thanks:)谢谢:)
Try these rules in .htaccess file:在 .htaccess 文件中尝试这些规则:
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.这将执行外部重定向,以防您不希望这样做,然后从上面删除R=301,
标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.