2017-04-16 136 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