2017-04-16 229 views
1

問號我有這個網站:重定向URL 301使用htaccess的

www.exampale.com/index.php?action=gallery & TAG_ID = X

X爲0至50,000數。

我想打一個301 redircet與htaccess的這個網站:

www.exampale.com/gallery/?tags=X

在這個網站同樣的事情:

www.exampale.com/?action=gallery & img_id = X (無的index.php)

要站點:

www.exampale.com/image/view/X

我試試這個代碼:

RewriteEngine On 
RewriteRule ^index.php?action=gallery&tag_id=([0-9]+)$ /gallery/?tags=$1 [R=301,NC] 
RewriteRule ^?action=gallery&img_id=([0-9]+)$ /image/view/$1 [R=301,NC] 

但它不是工作,當我嘗試沒有 「?」代碼運行良好。

有人能幫助我嗎?我必須在htaccess文件中編寫什麼代碼?

感謝您的幫助:-)

回答

0

QUERYSTRING 後的URL的一部分?不是RewriteRule模式匹配的一部分。你需要使用的RewriteCond

RewriteEngine on 

#index.php?action=gallery&tag_id=123 =>/gallery/?tags=123 
RewriteCond %{QUERY_STRING} ^action=gallery&tag_id=([0-9]+)$ [NC] 
RewriteRule ^index\.php$ http://example.com/gallery/?tags=%1 [NC,L,R] 
+0

感謝您匹配againg %{QUERY_STRING}變量!它正在工作,但是當我在另一個尺寸上嘗試時,這會造成問題。這是我寫的: RewriteCule%{QUERY_STRING}^action = gallery&img_id =([0-9] +)$ [NC] RewriteRule ^(。*)$/image/view /%1 [NC,L, R] – user3502020

+0

將**/image/view /%1 **更改爲**/image/view /%1 **,注意** ** ** char。從新的url中刪除舊的查詢字符串非常重要。 – starkeen

+0

再次感謝您! – user3502020