如何使用包含多个GET变量的.htaccess重写URL

时间:2016-01-02 19:11:55

标签: php apache .htaccess mod-rewrite url-rewriting

我使用.htaccess重写了我网站上所有网页的网址,除了这个网址;

https://www.atlasestateagents.co.uk/property_search.php?sort=3&availability=1&location=Liverpool&radius=50&min_price=&max_price=&min_beds=&max_beds=&type=&added=&available=1

由于GET变量,我完全不知道如何重写这个url。我很乐意将property_search.php替换为property_search,并保留其余网址。

我的.htaccess文件;

RewriteEngine On    # Turn on the rewriting engine

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.atlasestateagents.co.uk/$1 [R=301]

RewriteCond %{HTTP_HOST} !^www.atlasestateagents.co.uk$ [NC]
RewriteRule ^(.*)$ https://www.atlasestateagents.co.uk/$1 [R=301]

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

RewriteRule ^about/?$ about.php [NC,L]

RewriteRule ^contact/?$ contact.php [NC,L]

RewriteRule ^landlords/landlord-services-and-fees/?$ landlords/landlord-services-and-fees.php [NC,L]

RewriteRule ^vendors/vendors-services-and-fees/?$ vendors/vendors-services-and-fees.php [NC,L]

RewriteRule ^property-([0-9]+)/(.*)?$ view_property.php?property_id=$1 [NC,L]

Options -Indexes 

ExpiresActive On

ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"

ExpiresDefault "access plus 2 days"

1 个答案:

答案 0 :(得分:0)

我使用以下代码为自己想出了这个;

RewriteRule ^property-search/?$ property_search.php [NC,L,QSA]

QSA是主要部分,因为它将请求中的查询字符串附加到替换的URL