如何避免无限循环的时候htaccess的重写,以相同的htaccess的文件的副本? [英] How avoid infinite loop when htaccess rewrites to a copy of same htaccess-file?

查看:167
本文介绍了如何避免无限循环的时候htaccess的重写,以相同的htaccess的文件的副本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个htaccess文件:

I have this htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} =test.example.com [NC]
RewriteRule ^((?!test/).*)$ test/$1 [L,NC]

和同一个文件中的测试的目录完全一致的副本。当然,因此,这将导致一个无限循环,当第一个文件传给你再次运行规则的第二个文件。

And a completely identical copy of the same file in the "test" directory. So, of course, this leads to an infinite loop when the first file pass you to the second file running the rules again.

我试图添加规则的RewriteCond%{REQUEST_URI}!^测试[L,NC] 的希望REQUEST_URI主张真正的路径,而不是新的别名。然而,这并没有奏效。

I have tried add the rule RewriteCond %{REQUEST_URI} !^test [L,NC] in hope that REQUEST_URI stood for the real path and not the new "alias". However, it didn't worked.

有没有什么办法可以或许检查我们在哪个目录的状态使用?或者有什么其他的办法解决这个问题?随着基础上,以保持这两个文件的codeS相同。

Is there any way to maybe check which directory we are in to use in a condition? Or any other solution to this problem? With the basis to keep the both file's codes identical.

推荐答案

好吧,怪异,但现在我得到它的工作 - 只要是这样的:

Okay, weird, but I now got it to work - simply like this:

RewriteCond %{HTTP_HOST} =test.example.com [NC]
RewriteCond %{REQUEST_URI} !test [NC]
RewriteRule ^((?!test/).*)$ test/$1 [L,NC]

编辑:好像它仅适用于该起始页。其他网页上,一开始尾随路径的斜线被移除。

Seems like it only works for the startpage. On other pages, the beginning trailing slash of the path is being removed.

这篇关于如何避免无限循环的时候htaccess的重写,以相同的htaccess的文件的副本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆