0

这些 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 有页面和其他变量,但我真的不想进入那个蠕虫罐头。

4

1 回答 1

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]
于 2012-11-19T15:32:37.070 回答