[英]Simple rewrite rule for mod_rewrite
我需要写一个简单的 mod_rewrite 规则,如下:
something.php ==> somehting (just get rid of the .php)
something_else.php ==> something/else (replace _ with /)
所以,例如它会是这样的:
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
由于我不熟悉正则表达式,我认为问一个可以在 5 秒内完成此任务的人,而不是花几天(几周?:P)学习正则表达式和 mod_rewrite 会更简单。
谢谢:)
在 .htaccess 文件中尝试这些规则:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^([^_]+)_([^_]+)\.php/?$ /$1/$2 [R=301,L]
RewriteRule ^([^.]+)\.php/?$ /$1 [R=301,L]
这将执行外部重定向,以防您不希望这样做,然后从上面删除R=301,
标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.