繁体   English   中英

如何使htaccess忽略url的一部分

[英]How to make htaccess ignore part of url

我们有以下网址:example.com/automobile/?id=1234,出于seo的需要,它必须类似于example.com/automobile/passenger/ferrari/?id=1234

我们希望/ passenger / ferrari /是可选的,因为该数据与我们的查询及其动态无关。 因此,如果用户转到example.com/automobile/?id=1234或example.com/passenger/what/ever-is-write-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>

抱歉,它似乎不起作用。 也许我可以举一个例子来说明:检查一下:[link]( 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

它指向同一个地方

重定向

  • / passenger / what / ever-is-write-here / id = 1234

  • / automobile /?id = 1234

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM