2015-09-04 50 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

相關問題