动态URL重写搜索结果

时间:2019-01-21 19:56:37

标签: regex apache url mod-rewrite url-rewriting

是否可以使用 mod_rewrite 为搜索结果动态重写URL?

我正在尝试修复网站上的URL,以匹配Google的“搜索引擎友好”政策。 我想为3种类型的查询重写这些URL:

a )位置

  

example.com/search-auto/?style1_nonce=6ac0625a27&location= 伦敦&autobrand =&automodel =&modelyear =&fueltype =&priceRange = 540%2C43000&autotype =&searchauto =

成为:

example.com/search-auto/ 伦敦 /

其中伦敦可以是基于用户搜索的任何位置。

b )位置+品牌:

  

example.com/search-auto/?style1_nonce=6ac0625a27&location= 伦敦&autobrand = 宝马&automodel =&modelyear =&fueltype =&priceRange = 540%2C43000&autotype =&searchauto =

为:example.com/search-auto/ 伦敦 / 宝马 /

其中伦敦宝马可以是基于用户搜索的任何位置/品牌。

c )位置+品牌+型号:

  

example.com/search-auto/?style1_nonce=6ac0625a27&location= londo n&autobrand = 宝马&automodel = BMW + 1 + SERIES &modelyear = &fueltype =&priceRange = 540%2C43000&autotype =&searchauto =

为:example.com/search-auto/ 伦敦 / 宝马 / 宝马+1+系列 /

其中伦敦宝马宝马1系列可以是基于用户搜索的任何位置/品牌/型号。

请注意: 我知道我可以使用“静态”指令,例如:

# Rewrite --- https://example.com/search-auto/?style1_nonce=6ac0625a27&location=london&autobrand=audi&automodel=audi+a1&modelyear=&fueltype=&priceRange=540%2C43000&autotype=&searchauto= => https://example.com/search-auto/london/audi/audi+a1/
RewriteCond %{QUERY_STRING} (^|&)style1_nonce\=6ac0625a27($|&)
RewriteCond %{QUERY_STRING} (^|&)location\=london($|&)
RewriteCond %{QUERY_STRING} (^|&)autobrand\=audi($|&)
RewriteCond %{QUERY_STRING} (^|&)automodel\=audi\+a1($|&)
RewriteCond %{QUERY_STRING} (^|&)modelyear\=($|&)
RewriteCond %{QUERY_STRING} (^|&)fueltype\=($|&)
RewriteCond %{QUERY_STRING} (^|&)priceRange\=540%2C43000($|&)
RewriteCond %{QUERY_STRING} (^|&)autotype\=($|&)
RewriteCond %{QUERY_STRING} (^|&)searchauto\=($|&)
RewriteRule ^search\-auto/$ /search-auto/london/audi/audi+a1/?&%{QUERY_STRING}

但是style1_nonce = 6ac0625a27 是针对每个用户的,因此我无法为所有URL创建大量的重写指令列表。 我有希望吗?

克里斯,克里斯,

0 个答案:

没有答案