[英]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.