Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess是否使用重写?在url中_.htaccess_Redirect_Url Redirection - Fatal编程技术网

.htaccess是否使用重写?在url中

.htaccess是否使用重写?在url中,.htaccess,redirect,url-redirection,.htaccess,Redirect,Url Redirection,出于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

出于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]
不起作用:

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]
你知道怎么解决这个问题吗

我的总访问权限:

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] . 

查询字符串不是匹配的一部分,因此需要基于
%{query\u 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] . 

你下面的规则不行。只要把它放在你的顶部就行了。这证实了@anubhava所说的。第二个在本地的盒子上对我来说很好。你能用重写规则和apache的error.log中的几行代码来完成你的.htaccess吗?这两行代码我都分别在我的htaccess上尝试过。找不到我的日志。尝试使用phpmyadmin二进制日志,但无法查看它。清除缓存,使用不同的浏览器。我在日志文件夹80.101.162.xxx[11/Feb/2015:09:28:15+0100]“GET/?paginaid=1 HTTP/1.1”301 309“-”Mozilla/5.0(Windows NT 6.1;rv:35.0)Gecko/20100101 Firefox/35.0“
/index.php?paginaid=1
不能变为
/index.php/paginaid=1
,规则如下所示。您还有一些其他规则/代码未在此处显示。嘿,谢谢!,它确实可以工作,但所有其他URL都会被添加?q=。这是因为第二条规则。您正在尝试处理index.php的所有查询字符串吗?你需要它如何工作?(modx evolution)我需要处理所有页面,如普通->/about等。有一些旧URL被谷歌索引,需要将它们重定向到主页。所以现在剩下的就是删除?q=我猜。第一个规则集检查查询字符串并基于此重定向。您可以为需要重定向的URL复制该集。删除第二个,因为它是一个“一网打尽”(因为它没有查询字符串条件)!确实需要删除RewriteRule^index.php$[R=301,L]我已经更新了您的示例。