2010-08-31 126 views
0

我一直在試圖讓我的網址重寫。前4條規則至關重要,但它們與這條線相沖突:(我認爲)。衝突htaccess規則.php文件擴展仍然可訪問

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.#?\ ]+)\.php([#?][^\ ]*)?\ HTTP/ 

這將停止URL能夠像這樣www.example.com/page.php訪問和重定向將前4條規則,你可以以後www.example.com/page/

看到htaccess的,上述條件似乎沒有工作,即時通訊能夠訪問的URL像這樣:(

lovelakedistrict.com/lake-district-cottages.php/cottages/5/

很顯然,我應該是像這樣

lovelakedistrict.com/lake-district-cottages/cottages/5/

但是這仍然有效:)

lovelakedistrict.com/lake-district-cottages.php - > lovelakedistrict.com/lake -district-cottages/

這是我的htaccess文件 - 任何人都可以看到發生了什麼?

Options +FollowSymlinks 
Options +Indexes 

RewriteEngine on 
#these 4 rules stop being able to access pages like eg 
#/lake-district-cottages/?cottages=5/ 
#/lake-district-cottages/?cottages/5/  --> all direct to /lake-district-cottages/cottages/5/ 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+ 
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*(&+(.*))$ 
RewriteRule ^(.*[^/])/?$ /$1/%1/?%3 [N] 
RewriteCond %{REQUEST_URI} !^/result 
RewriteCond %{REQUEST_URI} !^/shop-result 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+ 
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*$ 
RewriteRule ^(.*[^/])/?$ /$1/%1/?%4 [L,R=301] 
RewriteCond %{REQUEST_URI} !^/result 
RewriteCond %{REQUEST_URI} !^/shop-result 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+ 
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*=/*([^&]*[^&/])/*(&+(.*))$ 
RewriteRule ^(.*[^/])/?$ /$1/%1/%2/?%4 [N] 
RewriteCond %{REQUEST_URI} !^/result 
RewriteCond %{REQUEST_URI} !^/shop-result 

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]+ 
RewriteCond %{QUERY_STRING} ^/*([^=&]*[^=&/])/*=/*([^&]*[^&/])/*$ 
RewriteRule ^(.*[^/])/?$ /$1/%1/%2/? [L,R=301] 
RewriteCond %{REQUEST_URI} !^/result 
RewriteCond %{REQUEST_URI} !^/shop-result 

# this stops you accessing pages with php extention eg 
#/lake-district-cottages.php --> directs to /lake-district-cottages/ 
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.#?\ ]+)\.php([#?][^\ ]*)?\ HTTP/ 

# this ignors the include folder and does not add trailing slash (so ajax file works) 
RewriteCond %1 !^include/ 
RewriteRule ^([^.]+)\.php$ /$1 [R=301,L] 

#this removes php extention 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

#this removes php extention and adds trailing slash 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/$ $1.php 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 

#these re-write urls allowing/to replace ? and = 
RewriteRule ^lake-district-cottages/cottages/([0-9]+) lake-district-cottages.php?cottages=$1 
RewriteRule ^lake-district-hotels/hotels/([0-9]+) lake-district-hotels.php?hotels=$1 
RewriteRule ^lake-district-bed-and-breakfast/bed-and-breakfast/([0-9]+) lake-district-bed-and-breakfast.php?bed-and-breakfast=$1 
RewriteRule ^lake-district-lodges/lodges/([0-9]+) lake-district-lodges.php?lodges=$1 
RewriteRule ^lake-district-cottages-shop/lake-district-book-shop/([0-9]+) lake-district-cottages-shop.php?lake-district-book-shop=$1 
RewriteRule ^lake-district-lodges/lodges/([0-9]+) lake-district-lodges.php?lodges=$1 
RewriteRule ^result/([a-zA-Z0-9])/([0-9]+) result.php?$1=$2 
RewriteRule ^shop-result/([a-zA-Z0-9])/([0-9]+) shop-result.php?$1=$2 

回答

1

條件模式不匹配網址包含PATH_INFO,但它簡化了一下,這樣的事情應該採取照顧:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php 
RewriteCond %1 !^include/ 
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301,L] 
+0

太謝謝你了蒂姆,你又一次已經把我排除在外了。非常感謝歡呼 – AJFMEDIA 2010-08-31 20:22:51

+0

沒問題,很高興聽到它的工作! – 2010-08-31 22:31:57