[英]How to use .htaccess mod rewrite to redirect php url as a string?
我一直在努力使:
http://site.com/file.php?x=foo
重定向到:
http://newsite.com/something/completely/different/
使用以下內容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^file\.php?x=foo$ http://newsite.com/something/completely/different/ [R=301,NC,L]
</IfModule>
但是它什么也沒做(只是加載相同的舊頁面,就像我從未接觸過htaccess一樣)。
有什么我想念的嗎?
非常感謝您的幫助!
?
.php
的末尾使最后一個p
可選(因此.phpx=foo
或.phx=foo
將匹配)。 實際上,它並不是比賽中的角色。 嘗試轉義?
喜歡: \\?
編輯 :
對於那些想知道解決方案是什么的人:
查詢字符串參數不會傳遞給RewriteRule
匹配的字符串。 因此,您必須首先在QUERY_STRING
上創建一個RewriteCond
,然后匹配不帶參數的url。 例如:
RewriteCond %{QUERY_STRING} x=foo
RewriteRule ^file\.php$ http://newsite.com/something/completely/different/ [R=301,NC,L]
可能/希望有一種更好的方法來執行此操作(因為此RewriteCond
將級聯為其他規則,這很煩人)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.