Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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 简单Htaccess重定向不工作_.htaccess_Url_Redirect - Fatal编程技术网

.htaccess 简单Htaccess重定向不工作

.htaccess 简单Htaccess重定向不工作,.htaccess,url,redirect,.htaccess,Url,Redirect,由于某种原因,这不起作用 Options +FollowSymLinks -MultiViews -Indexes RewriteEngine On RewriteBase / Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url 我不知道为什么。。。如果我将被重定向的URL替换为另一个不存在的URL(/helloworld),它将很好地重定向到新U

由于某种原因,这不起作用

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

Redirect 301 "/modules.php?name=News&file=article&sid=179" http://www.mysite.com/a/new/url
我不知道为什么。。。如果我将被重定向的URL替换为另一个不存在的URL(/helloworld),它将很好地重定向到新URL

它是不是在传染什么东西?我尝试了转义(/modules.php\?name=News&file=article&sid=179),但没有任何区别,仍然是404


感谢您的帮助

您无法匹配
重定向
指令中的查询字符串,您必须使用mod_rewrite和
%{query_string}
变量。试试这个:

RewriteCond %{QUERY_STRING} name=News&file=article&sid=179
RewriteRule ^/?modules\.php$ http://www.mysite.com/a/new/url? [R=301,L]
# There is a ? here to prevent query strings appending -----^

404?它重定向到哪一页谢谢你,好吧,这终于让我走了!!但现在的URL是:。我怎么能让URL是/a/new/URL而不将旧的东西粘贴在那里?@user1556073添加一个?在
/a/new/url
的末尾,它看起来是这样的:
RewriteRule^/?modules\.php$http://www.mysite.com/a/new/url? [R=301,L]
仍然做同样的事情。。。它将查询添加到新URL的末尾。我只想要一个普通的、新的URL,就像它在重写规则中出现的那样(我不希望最后出现查询)。谢谢@user1556073您已将规则更改为
RewriteRule^/?modules\.php$http://www.mysite.com/a/new/url? [R=301,L]
?注意
url
末尾的
。并确保没有
QSA
标志。因为当我测试该规则时,没有任何内容附加到末尾。这正是我所拥有的:RewriteRule^/?modules\.php$?[R=301,L]。我生成的URL如下所示:有什么想法吗