2015-09-04 33 views
0

我是一个新手.htaccess和正则表达式。我有一个脚本可以在本地运行,但是当我将它上传到活动服务器时,会导致无限循环。我怎样才能解决这个问题?在网站上,如果您未经身份验证加载http://example.com,则会将您带到登录表单的http://example.com/auth/,否则会显示http:///example.com/index.php的内容。它在本地工作正常,但是当我在活动服务器上传时,它找不到auth.php,因此它重定向到索引页面,并且由于用户未通过身份验证,因此发送到auth.php因此发生无限循环。请帮忙。谢谢。.htaccess导致在服务器上的无限循环,但在本地主机上工作

这是我的文件

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> 
+0

没有评论???真???非常感谢 – sammyukavi

回答

0

您可以重新排序规则:

Options +FollowSymLinks -MultiViews -Indexes 

<IfModule mod_rewrite.c> 
    DirectoryIndex index.php 
    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 [OR] 
    RewriteCond %{ENV:REDIRECT_STATUS} \d 
    RewriteRule^- [L] 

    # force trailing slash 
    RewriteCond %{DOCUMENT_ROOT}/$1\.php -f 
    RewriteRule ^(.+?[^/])$ $1/ [L,R=301] 

    RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?a=$2&id=$3 [QSA,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] 

    # rewrite extensionless php files 
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
    RewriteRule ^(.+?)/$ $1.php [L] 

    # finally, if not found 
    RewriteRule . index.php [L] 
</IfModule> 
+0

仍在循环。该网站托管在godaddy – sammyukavi

+0

GoDaddy有时没有启用htaccess。 .htaccess的位置可能是另一个问题。为什么'auth.php'没有找到? – anubhava

+0

.htaccess和auth.php位于相同的文件夹中,这是我为其提供网页的根文件夹,即我的htdocs。该网站是godaddy托管帐户上的子域。 – sammyukavi

相关问题