簡體   English   中英

如何使用mod_rewrite進行基本的URL重寫

[英]How to do a basic URL rewrite with mod_rewrite

我不明白為什么,但是當我使用這個:

#RewriteRule ^/?r/(.*)$ /index.php?n=$1 [L]

重寫mysite.com/r/somewhatmysite.com/index.php?r=somewhat的現場工作。

但是如果我使用這個:

#RewriteRule ^/?(.*)$ /index.php?name=$1 [L]

mysite.com/somewhat重寫為mysite.com/index.php?r=somewhat ,我的網站停止工作。

我不明白為什么。 有人可以幫我嗎?

如何將mysite.com/somewhat重寫為mysite.com/index.php?r=somewhat

您的第二條規則將導致無限循環,因為目標URI /index.php?r=somewhat也匹配.* 最終,它導致500個內部服務器錯誤。

要解決此問題,您需要避免使用RewriteCond這樣重寫文件和目錄:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.+)$ /index.php?r=$1 [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM