apache htaccess重写规则使重定向循环
Apache .htaccess URL 重写和重定向有一个非常奇怪的问题。这是我的设置: 我有一个 zend 应用程序,其单点入口 (index.php) 直接位于我的 apache 文档根目录下(称为“public”文件夹)。我的 public 文件夹下还有所有其他公共文件(图像、js、css 等)。在这里,我在“blog”文件夹下还有一个wordpress博客。测试文件夹也为空
问题
当我访问 example.com/blog 时,我被重定向到 http://www.example.com/blog(正确),然后转到 http ://www.example.com/blog/ (只是在末尾有一个额外的 / ),最后到 http://example.com/blog/——我们又回到了起点。循环继续。我不明白的是为什么wordpress会尝试删除www?我猜它是 wordpress,因为我的空测试文件夹表现得很好!
另一个奇怪的是,我实际上可以访问 www.example.com/blog/wp-login.php 或 example.com/blog/wp-login.php 并且它实际上加载了!!!!!
请帮忙。我真的很绝望:(非常感谢你
发生的其他事情:
当我访问 example.com 时,我正确地重定向到 www.example.com
当我访问 www.example.com 时,我正确地留在原地
当我访问 www.example.com/test 或 example.com/test 时,行为是正确的
Setup
所以我的 .htaccess 文件执行以下操作:
- 如果没有 www.,则添加它并执行操作。 代码。
这是我使用的 301重定向 RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http ://www.example.com/$1 [L,R=301]
- 如果请求不是针对资源(图像等)或博客,则通过重写 index.php 来加载 zend 应用程序
RewriteRule !((^博客(/)?.*$)|(.(js|ico|gif|jpg|jpeg|png|css|cur|JPG|html|txt))$)index.php 再次感谢
您的帮助! 阿里
Have a very strange problem with Apache .htaccess URL Rewriting and Redirection. Here's my setup:
I have a zend application with a single point of entry (index.php) directly under my apache document root (call this the "public" folder). I also have all other public files (images, js, css, etc.) under the public folder. Here, I also have a wordpress blog under the "blog" folder. There's an empty test folder too
The Problem
When I go to example.com/blog, I get redirected to http://www.example.com/blog (correctly), then to http://www.example.com/blog/ (just with an extra / at end), finally to http://example.com/blog/ -- and we're back where we started. The loop continues. What I don't understand is why would wordpress try to remove the www? I'm guessing it's wordpress because my empty test folder acts just fine!
Another weird this is that I can actually go to www.example.com/blog/wp-login.php or example.com/blog/wp-login.php and it actually LOADS UP!!!!!
PLEASE HELP. I"M REALLY DESPERATE :( Thank you very much
Other things that happen:
When I go to example.com, i correctly get redirected to www.example.com
When I go to www.example.com, i correctly stay where I am
When I go to www.example.com/test or example.com/test, behaviour is correct.
Setup
So my .htaccess file does the following:
- If there's no www., then add it and do a 301 redirect. Here's the code I use
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
- If the request is NOT for a resource (image, etc.), or the blog, then load zend application by rewriting to index.php
RewriteRule !((^blog(/)?.*$)|(.(js|ico|gif|jpg|jpeg|png|css|cur|JPG|html|txt))$) index.php
Thanks again for all your help!!!
Ali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你检查过Wordpress 中的设置吗?登录管理员并检查
Settings/Basics
(或者它的英文名称,我使用的是瑞典语翻译)。您可以在此处配置 WordPress 使用的 URL。如果设置时没有www.
,Wordpress 将尝试重定向。Did you check the settings in Wordpress? Log in to admin and check
Settings/Basics
(or what it is called in English, I'm using a Swedish translation). There you can configure which URL Wordpress is using. If it's set withoutwww.
, Wordpress will try to redirect.