2010-03-07 40 views
0

如何將index.php?search =重定向到基礎url?我使用此代碼試了一下:htaccess:如何將index.php?search =重定向到基址url

redirectMatch 301 ^/index.php?search=(.*) http://www.yoursite.com/ 

但隨後的頁面循環的代碼,如果我進入網站域名..

+0

你想重定向或重寫? – clyfe 2010-03-07 17:30:34

+0

我想301重定向 – elmas 2010-03-07 17:40:05

回答

1

mod_alias確實只對URL path工作,不是查詢:

mod_alias設計用於處理簡單的URL操作任務。對於更復雜的任務(如操作查詢字符串),請使用mod_rewrite提供的工具。

所以儘量mod_rewrite代替:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^search=(.*) 
RewriteRule ^/index\.php$ /? [L,R=301] 

或者更一般:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^([^&]*&+)*search=([^&]*) 
RewriteRule ^/index\.php$ /? [L,R=301] 

如果你想使用這個規則的.htaccess文件在你的根目錄下,刪除前導斜槓從模式。

0

嘗試:

RedirectMatch permanent ^/index.php?search=(.*)$ http://www.yoursite.com/ 
相關問題