简体   繁体   English

如何使htaccess忽略url的一部分

[英]How to make htaccess ignore part of url

We have this url: example.com/automobile/?id=1234 and for seo purposes need it to be like example.com/automobile/passenger/ferrari/?id=1234 我们有以下网址:example.com/automobile/?id=1234,出于seo的需要,它必须类似于example.com/automobile/passenger/ferrari/?id=1234

we want the /passenger/ferrari/ to be opcional since that data is not relevant for our query and its dynamic. 我们希望/ passenger / ferrari /是可选的,因为该数据与我们的查询及其动态无关。 So if a user goes to example.com/automobile/?id=1234 or to example.com/passenger/what/ever-is-written-here/?id=1234 goes to the the original url: example.com/automobile/?id=1234 因此,如果用户转到example.com/automobile/?id=1234或example.com/passenger/what/ever-is-write-here/?id=1234转到原始网址:example.com/automobile /?id = 1234

We are working with wordpress and have this rules now: 我们正在与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>

I'm sorry, but it doesn't seem to work. 抱歉,它似乎不起作用。 Maybe I can explain with an example: Check this: [link]( http://www.casaesol.com/imovel/apartamento/t2-2-quartos/venda/usado/guia-albufeira-faro/?id=2730876 ) 也许我可以举一个例子来说明:检查一下:[link]( http://www.casaesol.com/imovel/apartamento/t2-2-quartos/venda/usado/guia-albufeira-faro/?id=2730876

If you change the url part of /apartamento/t2-2-quartos/venda/usado/guia-albufeira-faro/ it will take you to the same url. 如果您更改/ apartamento / t2-2-quartos / venda / usado / guia-albufeira-faro /的网址部分,它将带您到相同的网址。 http://www.casaesol.com/imovel/?id=2730876 http://www.casaesol.com/imovel/?id=2730876

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

If you change the part of url: Apartamento-T1-Venda-Loures-Loures-Infantado to https://casa.sapo.pt/whateveryouwrite-d4acc412-3146-4f8b-bc8f-820cf556f853.html 如果您将网址的一部分更改:Apartamento-T1-Venda-Loures-Loures-Infantado更改为https://casa.sapo.pt/whateveryouwrite-d4acc412-3146-4f8b-bc8f-820cf556f853.html

It points to the same place 它指向同一个地方

To redirect 重定向

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

to

  • /automobile/?id=1234 / automobile /?id = 1234

put the following above your other rules : 将以下内容置于其他规则之上:

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