的.htaccess导致无限循环的现场服务器上,但工作在本地主机 [英] .htaccess causes infinite loop on live server but works on localhost
问题描述
我是一个新手的.htaccess和正则表达式。我的作品在当地,但是当我把它上传到一个活的服务器时,它会导致一个无限循环的脚本。我该如何解决这个问题?就当你加载网站 http://example.com
如果你是未经验证它把你带到 http://example.com/auth/
的登录表单,否则它会显示 HTTP的内容:///example.com/index.php
。它工作正常,在当地,但是当我上传的现场服务器上,它找不到 auth.php
,以便将其重定向到索引页面,因为用户没有通过验证其发送到 auth.php
这样的死循环。请帮忙。谢谢你。
这是我的文件
选项-Indexes
选项-MultiViews
选项+的FollowSymLinks
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
#删除PHP扩展(仅适用于GET方法)
的RewriteCond%{THE_REQUEST} ^ GET \ /(.+)\.php(?:\?|\s)[NC]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则^%1 /? [L,R = 301]
#不碰其他现有的文件/文件夹
的RewriteCond%{} REQUEST_FILENAME -f [OR]
的RewriteCond%{} REQUEST_FILENAME -d
重写规则^ - [L]
#力斜杠
的RewriteCond%{DOCUMENT_ROOT} / $ 1 \ .PHP -f
重写规则^(。+)$ $ 1 / [L,R = 301]
#重写无扩展名的PHP文件
的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f
重写规则^(+)/ $ $ 1.PHP [L]
到文件#rewrite路径如http://example.com/auth/recover到http://example.com/auth.php?a=recover
的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f
重写规则^([^ /] +)/([^ /] +)/ $ $ 1.PHP?a = $ 2 [QSA,L]
的RewriteCond%{DOCUMENT_ROOT} / $ 1.PHP -f
重写规则^([^ /] +)/([^ /] +)/([^ /] +)/ $ $ 1.PHP一个= $ 2及?ID = $ 3 [QSA,L]
#最后,如果未找到
重写规则^的index.php [L]
< / IfModule>
谷歌搜索和阅读,并试图和测试之后,我得到了解决GoDaddy的有趣的.htaccess probles的方式。我在这里解决了。
<一个href="http://serverfault.com/questions/720085/htaccess-causes-infinite-loop-on-live-server-but-works-on-localhost/">http://serverfault.com/questions/720085/htaccess-causes-infinite-loop-on-live-server-but-works-on-localhost/
I'm a newbie .htaccess and regex. I have a script that works locally but when I upload it to a live server it causes an infinite loop. How can I fix this? On the site when you load http://example.com
if you are unauthenticated it takes you to http://example.com/auth/
for a login form, else it displays the contents of http:///example.com/index.php
. It works fine locally but when I upload on a live server, it cannot find auth.php
so it redirects to the index page and because the user is not authenticated it sends to auth.php
thus the infinite loop. Please help. Thanks.
This is my file
Options -Indexes
Options -MultiViews
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# remove php extensions (only for GET method)
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.php(?:\?|\s) [NC]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ %1/? [L,R=301]
# don't touch other existing files/folders
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# force trailing slash
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+)$ $1/ [L,R=301]
# rewrite extensionless php files
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+)/$ $1.php [L]
#rewrite path to file eg http://example.com/auth/recover to http://example.com/auth.php?a=recover
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?a=$2 [QSA,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?a=$2&id=$3 [QSA,L]
# finally, if not found
RewriteRule ^ index.php [L]
</IfModule>
After googling and reading and trying and testing, I got the way to resolve godaddy's funny .htaccess probles. I solved it here.
这篇关于的.htaccess导致无限循环的现场服务器上,但工作在本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!