Apache 使用htaccess重定向带有问号的301 url

Apache 使用htaccess重定向带有问号的301 url,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我有这个网站: www.exampale.com/index.php?action=gallery&tag\u id=X X是一个介于0到50000之间的数字。 我想通过htaccess对该网站进行301重播: www.example.com/gallery/?tags=X 本网站中的内容相同: www.example.com/?action=gallery&img\u id=X(不含index.php) 至现场: www.exampale.com/image/view/X 我尝试以下代码: R

我有这个网站:

www.exampale.com/index.php?action=gallery&tag\u id=X

X是一个介于0到50000之间的数字。

我想通过htaccess对该网站进行301重播:

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

本网站中的内容相同:

www.example.com/?action=gallery&img\u 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文件中编写的代码是什么


感谢帮助:-)

查询在之后键入url部分?不是重写规则模式中匹配的一部分。您需要使用重写条件来匹配againing%{QUERY\u STRING}变量

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]

在重写规则的模式中,在之后查询url部分?不是匹配的一部分。您需要使用重写条件来匹配againing%{QUERY\u STRING}变量

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]

非常感谢。这是可行的,但当我尝试在另一个尺寸的它是一个问题。这就是我写的:RewriteCond%{QUERY_STRING}^action=gallery&img_id=([0-9]+)$[NC]RewriteRule^(.*)$/image/view/%1[NC,L,R]将/image/view/%1更改为/image/view/%1,注意到了吗?烧焦这对于从新url中删除旧的查询字符串非常重要。谢谢!这是可行的,但当我尝试在另一个尺寸的它是一个问题。这就是我写的:RewriteCond%{QUERY_STRING}^action=gallery&img_id=([0-9]+)$[NC]RewriteRule^(.*)$/image/view/%1[NC,L,R]将/image/view/%1更改为/image/view/%1,注意到了吗?烧焦这对于从新url中删除旧查询字符串很重要。