使用.htaccess重写URL

时间:2012-12-08 12:18:21

标签: .htaccess mod-rewrite url-rewriting

我正在尝试重写我的网址,以便它们对搜索引擎友好。

示例网址为:

http://www.example.com/?Products=Displays&SubCat=Chalkboards-and-Accessories&Item=Budget-Framed-Chalkboards

我想的可能是这样的:

http://www.example.com/Chalkboards-and-Accessories/Budget-Framed-Chalkboards

3 个答案:

答案 0 :(得分:1)

取代使用{Domain} / Chalkboards-and-Accessories / Budget-Framed-Chalkboards网址, 我建议你使用{Domain} / 产品/黑板 - 和配件/咖啡馆和绳索 - 障碍系统,因为在你的网站中你有{Domain} /?关于。

试试这个,

RewriteEngine On
RewriteCond %{HTTP_HOST} !^catalogue\.signalight\.co\.uk$
RewriteCond %{HTTP_HOST} !^blog\.signalight\.co\.uk$

#RewriteCond %{REQUEST_URI} !^/catalogue
#RewriteCond %{REQUEST_URI} !^/blog

RewriteRule ^([a-zA-Z0-9-_]+)/?$                                    ?$1 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/?$                   ?$1=$2 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/?$  ?$1=$2&SubCat=$3 [L]
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$  ?$1=$2&SubCat=$3&Item=$4 [L]

答案 1 :(得分:0)

答案 2 :(得分:0)

你可以试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING}  ^.*&\w+=([a-zA-Z0-9-_]*)&\w+=([a-zA-Z0-9-_]*).*$ 
RewriteRule .* %1/%2?  [L]

它将取代:

http://www.signalight.co.uk/?par1=val1&par2=val2&par3=val3使用此

http://www.signalight.co.uk/val2/val3