任何想法如何改變這個mod重寫劇本 刪除的.html不工作,如果我刪除 「.HTML」重新寫USERPROFILE URL(remove.html)
RewriteRule ^([^/]*)\.html$ /userprofile.php?member_id=$1 [L]
作品作爲
http://site.com/12.html
但是想它作爲
http://site.com/12
謝謝
任何想法如何改變這個mod重寫劇本 刪除的.html不工作,如果我刪除 「.HTML」重新寫USERPROFILE URL(remove.html)
RewriteRule ^([^/]*)\.html$ /userprofile.php?member_id=$1 [L]
作品作爲
http://site.com/12.html
但是想它作爲
http://site.com/12
謝謝
MODIFIED: 我測試了以下內容,它們在運行Apache的CentOS服務器上工作。
對於目錄改寫:
RewriteRule ^/test/(.*)$ http://www.google.com [L,R]
將重定向到http://www.site.com/testhttp://www.google.com。
對於目錄中的所有文件,這將工作:
RewriteRule ^/test/([^/]*)(.*)$ http://www.google.com [L,R]
將重定向www.site.com/test/12.html或www.site.com/test/298.aspx或其他任何將「test」目錄中的文件複製到www.google.com。
所以這可能是更你在找什麼:
RewriteRule ^/12/([^/]*)(.*)$ /userprofile.php?member_id=$1 [L,R]
原貼:
我相信這是你在找什麼:
RewriteRule ^([^/]*)(.*)$ /userprofile.php?member_id=$1 [L]
那是如果你正在嘗試重寫文件...
如果你想對一個目錄進行重寫,它會略有不同。
您還需要刪除反斜槓(「\ .html」)。
爲了使.html
可選,把它放在一個組中,並使用?
量詞:
RewriteRule ^([^/]*)(\.html)?$ /userprofile.php?member_id=$1 [L]
但由於這種模式現在也可以匹配任何單個路徑段,你應該使之更加具體,只匹配您的特定網址路徑模式。在這種情況下,\d+
而不是[^/]*
將是更好的選擇:
RewriteRule ^(\d+)(\.html)?$ /userprofile.php?member_id=$1 [L]
沒有工作。內部服務器錯誤 – 2011-02-11 20:24:24
您是否試圖用任何文件類型對名爲「12」的頁面進行重寫,或者您是否正在對名爲「12」的目錄進行重寫? – Eli 2011-02-11 21:03:24