如何使htaccess忽略url的一部分

时间:2016-06-27 13:41:36

标签: php wordpress .htaccess

我们有这个网址:example.com/automobile/?id=1234,对于seo目的,需要它像example.com/automobile/passenger/ferrari/?id=1234

我们希望/ passenger / ferrari /是opcional,因为该数据与我们的查询及其动态无关。 因此,如果用户访问example.com/automobile/?id=1234或者访问example.com/passenger/what/ever-is-written-here/?id=1234,请转到原始网址:example.com/automobile /?ID = 1234

我们正在使用wordpress并立即制定此规则:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.php [L]
</IfModule>

对不起,但它似乎无法奏效。 也许我可以用一个例子来解释: 检查一下: [链接]( http://www.casaesol.com/imovel/apartamento/t2-2-quartos/venda/usado/guia-albufeira-faro/?id=2730876

如果您更改/ apartamento / t2-2-quartos / venda / usado / guia-albufeira-faro /的网址部分,它将转到相同的网址。 http://www.casaesol.com/imovel/?id=2730876

或另一个例子: https://casa.sapo.pt/Apartamento-T1-Venda-Loures-Loures-Infantado-d4acc412-3146-4f8b-bc8f-820cf556f853.html

如果您更改网址的部分:Apartamento-T1-Venda-Loures-Loures-Infantado https://casa.sapo.pt/whateveryouwrite-d4acc412-3146-4f8b-bc8f-820cf556f853.html

它指向同一个地方

1 个答案:

答案 0 :(得分:1)

重定向

  • /乘客/什么/不断被写入 - 在这里/?ID = 1234

  • /汽车/?ID = 1234

将以下内容置于其他规则之上:

RewriteEngine on
RewriteCond %{THE_REQUEST} /passenger/.+\?id=([0-9]+) [NC]
RewriteRule ^ /automobile/?id=%1 [L,R,NE]
相关问题