2012-11-19 48 views
0

這些htaccess的規則,我發瘋,我試過的例子和發電機的負荷,並得到knowhere ...的.htaccess重寫細節

我的htaccess如下所示

Options +FollowSymLinks 
DirectoryIndex index.php 

RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www.domain.com [NC] 
RewriteRule ^(.*)$ http://domain.co.uk/$1 [L,R=301] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L] 

RewriteRule ^location/([^/]*)\.html$ /location.php?location=$1 [R=301,L] 
RewriteRule ^([^/]*)\.html$ /search.php?searching=yes&s=$1 [R=301,L] 

我試圖讓

http://www.domain.com  
to http://domain.com (works) 

http://domain.com/index.php 
to http://domain.com (works) 

全部重寫PHP擴展到html即

http://domain.com/location.php 
to http://domain.con/location.html (doesnt work) 

http://domain.com/about.php  
to http://domain.con/about.html (doesnt work) 

http://domain.com/support.php 
to http://domain.com/support.html (doesnt work) 

改寫以下變量

http://domain.com/location.php?location=bedfordshire 
to http://domain.com/location/bedfordshire.html (doesnt work) 

http://domain.com/search.php?searching=yes&s=langster&pmin=&daf=&search=&pmax=&dab= 
to http://domain.com/langster.html (doesnt work) 

喜歡的index.php,location.php和search.php中有些有頁面和其他變量,但我真的不希望進入蠕蟲了可以呢。

回答

0
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] 
RewriteRule ^(.*)$ http://domain.co.uk/$1 [L,R=301] 

RewriteRule ^index\.php$/[R=301,L] 

RewriteCond %{REQUEST_URI} ^/location\.php$ 
RewriteCond %{QUERY_STRING} ^location=(.+)$ 
RewriteRule .* /location/%1.html? [R=301,L] 

RewriteCond %{REQUEST_URI} ^/search\.php$ 
RewriteCond %{QUERY_STRING} ^.*&s=([^&]+) 
RewriteRule .* /%1.html? [R=301,L] 

RewriteCond %{QUERY_STRING} ="" 
RewriteRule ^(.*)\.php$ /$1.html [R=301,L] 

...以及處理重定向請求,並將其傳遞迴PHP作爲參數,使用以下規則:

RewriteRule ^location/(.+)\.html$ /location.php?noloop=1&location=$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)\.html$ /search.php?s=$1 [L] 
+0

。在這些工作(謝謝)......但需要實際的文件在那裏,有沒有辦法做到這一點? – user1639745

+0

@ user1639745用新的部分更新了答案。看看 –

+0

這是一個沒有結束的循環......它只是在一個圓圈內繼續重定向:) – user1639745