2017-07-27 66 views
0

我遇到了爲我的網站設置的htaccess文件的問題。問題是,當我訪問沒有斜槓的特定位置鏈接:htaccess導致瀏覽器使用正斜槓繼續重定向

example.com/location/city

然後重定向到:

example.com/location///////

並保持重寫每次添加正斜槓。

這隻發生在我從最後刪除正斜槓時。如果正斜槓在那裏,頁面加載正常。網站上的所有其他頁面都正常工作。

這裏是我的代碼:

RewriteEngine On 
RewriteBase/

##################################################### 
# Rewrite specific pages - listings 
RewriteCond %{THE_REQUEST} \ /+listings\.php\? [NC] 
RewriteCond %{QUERY_STRING} (?:^|&)packageType=([^&]+) [NC] 
RewriteCond %{QUERY_STRING} !&packageTypeSub=([^&]+) 
RewriteRule^%1/? [R=301,L] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^([^/]+)/([^/]+)?$ listings.php?packageType=$1 [L,QSA] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^([^/]+)/([^/]+)?$ listings.php?packageType=$1&packageTypeSub=$2 [L,QSA] 


##################################################### 
# Rewrite specific pages - location (used for all location except provinceState) 
RewriteCond %{THE_REQUEST} \ /+location\.php\? [NC] 
RewriteCond %{QUERY_STRING} (?:^|&)place=([^&]+) [NC] 
RewriteCond %{QUERY_STRING} !&packageType=([^&]+) 
RewriteRule^location/%1/? [R=301,L] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^location/([^/]+)/([^/]+)?$ location.php?place=$1 [L,QSA] 

# Rewrite specific pages - location (provinceState) 
RewriteCond %{THE_REQUEST} \ /+location\.php\? [NC] 
RewriteCond %{QUERY_STRING} (?:^|&)provinceState=([^&]+) [NC] 
RewriteCond %{QUERY_STRING} !&packageType=([^&]+) 
RewriteRule^location/provinceState-%1/? [R=301,L] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^location/([^/]+)/([^/]+)?$ location.php?provinceState=$1 [L,QSA] 

# Allow place, packageType and packageTypeSub (for dropdowns) 
RewriteCond %{THE_REQUEST} \ /+location\.php\? [NC] 
RewriteCond %{QUERY_STRING} (?:^|&)place=([^&]+)&packageType=([^&\s]+)&packageTypeSub=([^&\s]+) [NC] 
RewriteRule^location/%1/%2/%3/? [R=301,L] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^location/([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ location.php?place=$1&packageType=$2&packageTypeSub=$3 [L,QSA] 

# Allow place, packageType and packageTypeSub (for dropdowns provinceState) 
RewriteCond %{THE_REQUEST} \ /+location\.php\? [NC] 
RewriteCond %{QUERY_STRING} (?:^|&)provinceState=([^&]+)&packageType=([^&\s]+)&packageTypeSub=([^&\s]+) [NC] 
RewriteRule^location/provinceState-%1/%2/%3/? [R=301,L] 

RewriteCond %{REQUEST_URI} !(upload-images|email|email-newsletter|login|logout|pml|search|download_pdf|mywebtool|mywebtool_data|mywebtool-enquiries|phpmyadmin|test) [NC] 
RewriteRule ^location/([^/]+)/([^/]+)/([^/]+)/([^/]+)?$ location.php?provinceState=$1&packageType=$2&packageTypeSub=$3 [L,QSA] 


##################################################### 
# All other pages 
RewriteCond %{DOCUMENT_ROOT}/$1\.php [NC] 
RewriteRule ^([^/.]+)$ $1.php [L] 

# Location of 404 page if errors 
ErrorDocument 404 http://example.com/404-not-found 

Header add Access-Control-Allow-Origin "*" 

,第一部分是對列表頁面,而且位置頁面的第二部分。出於某種原因,位置鏈接正在傳遞到列表部分並導致問題。如果我禁用代碼的部分/部分,問題就會消失。

任何想法?

回答

0

確實很奇怪。我假設它每次重定向到另一個頁面時都會增加一個額外的正斜槓。此問題的解決方法是僅強制結束斜線(s)不出現。

.htaccess文件中使用此:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} (.+)/$ 
RewriteRule^%1 [R=301,L] 

測試此之前,請務必清除緩存。

+0

感謝您的幫助,雖然沒有工作。 –

相關問題