Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/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重定向时出现的问题_.htaccess_Redirect_Infinite Loop - Fatal编程技术网

从无限循环中断.htaccess重定向时出现的问题

从无限循环中断.htaccess重定向时出现的问题,.htaccess,redirect,infinite-loop,.htaccess,Redirect,Infinite Loop,所以我在我的博客上寻求帮助,浏览了互联网,仔细研究了你们以前在这里提供的例子,但我仍然找不到一个有效的答案 简单地说,我试图从站点A获取所有引用到我站点的流量,并将其重定向到我域内的页面B。我已经让重定向完美地工作,但我无法让它突破无限循环。如蒙协助,将不胜感激 代码如下所示,尽管已从我使用的特定页面匿名化: <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteC

所以我在我的博客上寻求帮助,浏览了互联网,仔细研究了你们以前在这里提供的例子,但我仍然找不到一个有效的答案

简单地说,我试图从站点A获取所有引用到我站点的流量,并将其重定向到我域内的页面B。我已经让重定向完美地工作,但我无法让它突破无限循环。如蒙协助,将不胜感激

代码如下所示,尽管已从我使用的特定页面匿名化:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !filename\.html$
RewriteCond %{HTTP_REFERER} ^http://online\.webpage\.com.* [NC]
RewriteRule (.*) http://www.wallsofthecity.net/year/mo/filename.html [L]
</IfModule>
正如我所说,RewriteRule工作得很好,但是第一个RewriteCond在适当的页面上时似乎没有标记,只是不断地重定向用户,这是一种令人厌恶的行为。我一直在使用这个网站:检查我的代码,虽然有用,但它并没有给我任何好的答案

谢谢你能提供的一切帮助

更新:

下面是完整的.htacces文件,因为这可能会使事情变得更简单:

<IfModule mod_rewrite.c>
RewriteEngine On

# Force an external redirect to this page for referrals from that site
# This page *must* exist to prevent a loop (which it does, I checked :P)
RewriteCond %{HTTP_REFERER} ^http://mikeb302000\.blogspot\.com.* [NC]
RewriteCond %{REQUEST_URI} !=/2010/04/cruisin-for-a-bruisin.html
RewriteRule . /2010/04/cruisin-for-a-bruisin.html [R,L]

# This scenario performs no rewrite, so it should actually just be handled by
# the RewriteConds below (they won't match), but I didn't test that
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

Redirect permanent /index.xml http://www.wallsofthecity.net/feed/
Redirect permanent /rss.xml http://www.wallsofthecity.net/feed/
Redirect permanent /atom.xml http://www.wallsofthecity.net/feed/atom/
Redirect permanent /12_tribes http://www.wallsofthecity.net/category/12-tribes
Redirect permanent /as_i_say_not_do http://www.wallsofthecity.net/category/as-i-say-not-do
Redirect permanent /bigotry_exposed http://www.wallsofthecity.net/category/bigotry-exposed
Redirect permanent /commercial_appeal http://www.wallsofthecity.net/category/commercial-appeal
Redirect permanent /cowardice_on_parade http://www.wallsofthecity.net/category/cowardice-on-parade
Redirect permanent /crosscountry_jaunt http://www.wallsofthecity.net/category/crosscountry-jaunt
Redirect permanent /digital_real_estate http://www.wallsofthecity.net/category/digital-real-estate
Redirect permanent /fools_and_jesters http://www.wallsofthecity.net/category/fools-and-jesters
Redirect permanent /for_hire http://www.wallsofthecity.net/category/for-hire
Redirect permanent /me_myself_and_i http://www.wallsofthecity.net/category/me-myself-and-i
Redirect permanent /musings_of_a_madman http://www.wallsofthecity.net/category/musings-of-a-madman
Redirect permanent /one-line_review http://www.wallsofthecity.net/category/one-line-review
Redirect permanent /patron_polity_of_perforation http://www.wallsofthecity.net/category/patron-polity-of-perforation
Redirect permanent /peoples_republic_of_kalifornistan http://www.wallsofthecity.net/category/peoples-republic-of-kalifornistan
Redirect permanent /sensor_ping http://www.wallsofthecity.net/category/sensor-ping
Redirect permanent /serenity http://www.wallsofthecity.net/category/serenity
Redirect permanent /simon_jester http://www.wallsofthecity.net/category/simon-jester
Redirect permanent /the_funnies http://www.wallsofthecity.net/category/the-funnies
Redirect permanent /the_mat http://www.wallsofthecity.net/category/the-mat
Redirect permanent /things_that_go_boom http://www.wallsofthecity.net/category/things-that-go-boom
Redirect permanent /toysgizmosgadgets http://www.wallsofthecity.net/category/toysgizmosgadgets
Redirect permanent /urk http://www.wallsofthecity.net/category/urk
Redirect permanent /window_on_the_world http://www.wallsofthecity.net/category/window-on-the-world

</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

注意:它似乎仍然不起作用。测试时间:

我要尝试的第一件事是更改重写条件,如下所示:

RewriteCond %{REQUEST_FILENAME} !^.*filename\.html$
我认为Apache不应该强制匹配从字符串的开头开始,但是如果它出于任何原因这样做,并且如果这是问题的原因,那么这个更改将修复它

作为替代方法,只需完全删除第一个重写条件,并将重写规则更改为

RewriteRule !year/mo/filename.html http://www.wallsofthecity.net/year/mo/filename.html
编辑:让我们尝试此操作,以限制文章长度:

外部重定向:

RewriteEngine On

# Force an external redirect to this page for referrals from that site
# This page *must* exist to prevent a loop (which it does, I checked :P)
RewriteCond %{HTTP_REFERER} ^http://mikeb302000\.blogspot\.com.* [NC]
RewriteCond %{REQUEST_URI} !=/2010/04/cruisin-for-a-bruisin.html
RewriteRule . /2010/04/cruisin-for-a-bruisin.html [R,L]

# This scenario performs no rewrite, so it should actually just be handled by
# the RewriteConds below (they won't match), but I didn't test that
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

# With an external redirect, the first RewriteCond catches our referrer redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# These are always evaluated after mod_rewrite stuff, but use the original
# REQUEST_URI unless we explicitly passed it through to handlers later in
# the chain (via the PT flag)
Redirect permanent ... (trimmed)
RewriteEngine On

# Force an external redirect to this page for referrals from that site
# This page *must* exist to prevent a loop (which it does, I checked :P)
RewriteCond %{HTTP_REFERER} ^http://mikeb302000\.blogspot\.com.* [NC]
RewriteCond %{REQUEST_URI} !=/2010/04/cruisin-for-a-bruisin.html
RewriteRule . /2010/04/cruisin-for-a-bruisin.html [L]

# This scenario performs no rewrite, so it should actually just be handled by
# the RewriteConds below (they won't match), but I didn't test that
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

# With an internal redirect, we have to do an extra check to prevent this rewrite
# with our referrer redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0 !-f
RewriteRule .* /index.php [L]

# These are always evaluated after mod_rewrite stuff, but use the original
# REQUEST_URI unless we explicitly passed it through to handlers later in
# the chain (via the PT flag)
Redirect permanent ... (trimmed)
内部重定向:

RewriteEngine On

# Force an external redirect to this page for referrals from that site
# This page *must* exist to prevent a loop (which it does, I checked :P)
RewriteCond %{HTTP_REFERER} ^http://mikeb302000\.blogspot\.com.* [NC]
RewriteCond %{REQUEST_URI} !=/2010/04/cruisin-for-a-bruisin.html
RewriteRule . /2010/04/cruisin-for-a-bruisin.html [R,L]

# This scenario performs no rewrite, so it should actually just be handled by
# the RewriteConds below (they won't match), but I didn't test that
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

# With an external redirect, the first RewriteCond catches our referrer redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# These are always evaluated after mod_rewrite stuff, but use the original
# REQUEST_URI unless we explicitly passed it through to handlers later in
# the chain (via the PT flag)
Redirect permanent ... (trimmed)
RewriteEngine On

# Force an external redirect to this page for referrals from that site
# This page *must* exist to prevent a loop (which it does, I checked :P)
RewriteCond %{HTTP_REFERER} ^http://mikeb302000\.blogspot\.com.* [NC]
RewriteCond %{REQUEST_URI} !=/2010/04/cruisin-for-a-bruisin.html
RewriteRule . /2010/04/cruisin-for-a-bruisin.html [L]

# This scenario performs no rewrite, so it should actually just be handled by
# the RewriteConds below (they won't match), but I didn't test that
RewriteCond %{REQUEST_URI} ^/(stats|failed_auth\.html).*$ [NC]
RewriteRule . - [L]

# With an internal redirect, we have to do an extra check to prevent this rewrite
# with our referrer redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0 !-f
RewriteRule .* /index.php [L]

# These are always evaluated after mod_rewrite stuff, but use the original
# REQUEST_URI unless we explicitly passed it through to handlers later in
# the chain (via the PT flag)
Redirect permanent ... (trimmed)
再次编辑:

让我们也来尝试一些诊断…您能将其置于.htaccess文件中的其他规则之上吗


谢谢你的尝试,大卫,但这两个似乎都不起作用。如果它为您或任何其他人提供了任何信息,那么上面的工具将指示标题返回Location:for every repeat redirect,并且该位置地址将重定向浏览器。。。即使浏览器可能已经在那个页面上了。。。这让我很困惑:。@linoge:我想这就是正在发生的事情,尽管这似乎有点奇怪,因为Apache应该剥离http://www.wallsofthecity.net 部分无论如何,我想知道是否还有其他重写规则会干扰这些。哦,等等-我更新了我的重写规则以删除模式中的前导斜杠,因为你没有将其包含在.htaccess文件中。尝试更新的版本,看看是否有效。如果没有,您使用的是什么版本的Apache?在这个序列之后有重写规则,但之前没有,并且[L]标记是否应该阻止.htaccess文件继续进行?把前面的斜杠砍掉了,没有乐趣。提供完整的地址,没有欢乐。Dreamhost以其无穷的智慧似乎已经将ServerTokens设置为Prod,因此我不能完全确定我正在运行的Apache版本:[L]停止对当前请求应用任何进一步的规则,但是如果Apache创建了一个外部重定向,听起来像是您正在做的事情或子请求,整个过程从头开始,因此[L]标志可能不是全部。配置中的其他地方一定发生了什么,因为我给你的修改过的重写规则实际上是mod_rewrite,相当于a=false;我的意思是,它本身不应该能够引起循环,而且它显然不能。如果我们有实际的URL来运行测试,这可能会很有帮助。在Dreamhost上托管此网页是否有帮助/重要?有什么全局函数/变量我应该注意/查找吗?嗯。。。据我所知,Dreamhost没有什么特别奇怪的地方,但我从未亲自使用过,所以我不能肯定。可以肯定的是,您的.htaccess文件位于哪里?这是唯一有重写规则的地方吗?一定有什么解释,呵呵。htaccess文件位于网页的根目录中。在上面的代码之后,在一个单独的RewriteEngine On声明中有一整串重定向永久命令,以弥补从MovableType更改为Wordpress和断开链接的不足,然后是以下代码:RewriteEngine On RewriteBase/RewriteCond%{REQUEST_FILENAME}-f RewriteCond%{REQUEST_FILENAME}-重写规则/但是,第一个[L]标记在此之前是否应该停止.htaccess文件?那里有断线,我就是不能让它们粘在一起。啊,我明白了。path/to/filename.html是否实际指向一个真实的文件,或者您是否打算让WordPress处理它?在mod_rewrite将新URL作为内部重定向发送到Apache之前,L停止应用任何重写规则。因为您的内部重定向指向相同的目录层次结构,所以在处理新请求时会再次计算.hatcess 这是一份对上帝诚实的文件,尽管它似乎对我没有什么好处。现在我知道[L]只在每个mod_rewrite调用中停止,我压缩了三个单独的mod_rewrite函数。。。但即便如此,这似乎也不是一个有效的解决方案。