Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Apache 301重定向/重写导致循环错误_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Apache 301重定向/重写导致循环错误

Apache 301重定向/重写导致循环错误,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我得到一个重定向循环,代码如下。我怎样才能修好它 第一部分将/links.php重定向到/linked 第二部分重写/链接到/links.php RewriteBase/domain.com RewriteRule ^links\.php$ linked? [NS,R=301,L] RewriteRule ^linked$ links.php?redirect=no [NS] 两种方法都有效,所以我接受第一种方法。再次感谢你 您需要检查在第二条规则中添加的查询字符串,因此在第一条规则前面

我得到一个重定向循环,代码如下。我怎样才能修好它

  • 第一部分将/links.php重定向到/linked
  • 第二部分重写/链接到/links.php
RewriteBase/domain.com

RewriteRule ^links\.php$ linked? [NS,R=301,L]
RewriteRule ^linked$ links.php?redirect=no [NS]


两种方法都有效,所以我接受第一种方法。再次感谢你

您需要检查在第二条规则中添加的查询字符串,因此在第一条规则前面添加一个RewriteCond:

RewriteCond %{QUERY_STRING} !redirect=no

您需要检查在第二条规则中添加的查询字符串,因此在第一条规则前面添加一个RewriteCond:

RewriteCond %{QUERY_STRING} !redirect=no

您可以使用重写条件匹配原始url,而不是(可能已经)重写的url:

RewriteCond %{THE_REQUEST} links\.php
RewriteRule ^links\.php$ linked? [R=301,L]
RewriteRule ^linked$ links.php [L]

您可以使用重写条件匹配原始url,而不是(可能已经)重写的url:

RewriteCond %{THE_REQUEST} links\.php
RewriteRule ^links\.php$ linked? [R=301,L]
RewriteRule ^linked$ links.php [L]