2014-10-03 124 views
1

我需要將一個動態URL重定向到另一個,但參數略有更改。這是原來的URL:htaccess將動態URL重定向到另一個動態URL

http://www.EXAMPLE.com/index.php?main_page=index&cPath=5 

,它需要被重定向到

http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 

我已經嘗試了許多不同的變化,卻沒有一個似乎工作。

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$ 
RewriteRule ^/(index\.php|)$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [L,R=301] 

我要瘋了這... ...任何人都可以請點我在正確的方向,告訴我什麼,我做錯了什麼?

回答

1

我相信主導斜線是您的模式中的問題。試試這個規則在你的根的.htaccess:

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=5$ [NC] 
RewriteRule ^/?(index\.php)?$ /$1?main_page=index&cPath=25 [NC,L,R=301] 
+0

aaaah,這麼漂亮的解決方案,非常感謝! – user1078494 2014-10-03 08:42:30

+0

不客氣,很高興它解決了。 – anubhava 2014-10-03 08:48:43

0

也許沒有條件?

RewriteEngine on 
rewriterule ^index.php?main_page=index&cPath=5$ http://www.EXAMPLE.com/index.php?main_page=index&cPath=25 [r=301,nc] 
+1

QUERY_STRING不重寫規則可用,因爲與路徑重寫規則的交易,這樣的RewriteCond應使用。 – Cheery 2014-10-03 07:27:02