.htaccess重写使用?在url中

uttx8gqw  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(122)

由于SEO原因,我需要重定向旧URL:/index.php?paginaid=1到www.example.com/
但是当我尝试像下面这样时,它变成了www.example.com/paginaid=1
不起作用:

RewriteRule ^index.php?paginaid=1$ http://www.example.com/ [R=301,L]

不起作用:

RewriteCond %{QUERY_STRING}  ^paginaid=1$ [NC]
RewriteRule ^index\.php$ http://www.example.com? [R=301,NE,NC,L]

有办法解决吗?
我的总.htaccess:

RewriteRule ^index.php\?paginaid=1$ http://www.example.com/ [R=301,L]

#RewriteRule ^index.php?paginaid=1$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=2$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=3$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=4$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=5$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=6$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=7$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=8$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=9$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=10$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=12$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?paginaid=13$ http://www.example.com/ [R=301,L]
RewriteRule ^index.php$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=archief$ http://www.example.com/ [R=301,L]
#RewriteRule ^argeweb/weblog/2007/18/oebele.php$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=archief&aid=2006_9$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=archief&aid=2007_1$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=archief&aid=2008_10$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=categorie&cid=1$ http://www.example.com/ [R=301,L]
#RewriteRule ^index.php?page=archief&aid=2007_5$ http://www.example.com/ [R=301,L]
#RewriteRule ^argeweb/weblog/index.php?page=archief$ http://www.example.com/ [R=301,L]
#RewriteRule ^argeweb/weblog/index.php?page=links$ http://www.example.com/ [R=301,L]

AddDefaultCharset utf-8

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

RewriteRule ^(manager|assets)/.*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*)$ http://www.%1/$1 [R=permanent,L] .
yrdbyhpb

yrdbyhpb1#

查询字符串不是匹配的一部分,因此需要包含一个基于%{QUERY_STRING}的重写条件。
此外,如果重写位置没有添加任何内容,.htaccess似乎会附加原始查询字符串,因此要解决这个问题,您需要添加一个单独的?

RewriteCond %{QUERY_STRING} ^paginaid=1$
RewriteRule ^index.php$ http://www.example.com/? [R=301,L]

此外,您的全局index.php规则覆盖了paginaid规则,因此将其移到上面。以下是使用paginaid规则的完整.htaccess:

AddDefaultCharset utf-8

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^paginaid=1$
RewriteRule ^index.php$ http://www.example.com? [R=302,L]
RewriteCond %{QUERY_STRING} ^paginaid=2$
RewriteRule ^index.php$ http://www.example.com? [R=302,L]
RewriteCond %{QUERY_STRING} ^paginaid=3$
RewriteRule ^index.php$ http://www.example.com/? [R=302,L]

RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]

RewriteRule ^(manager|assets)/.*$ - [L]
RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*)$ http://www.%1/$1 [R=permanent,L] .

相关问题