user4766697
user4766697

Reputation: 49

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

we want the /passenger/ferrari/ to be opcional since that data is not relevant for our query and its dynamic. 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

We are working with wordpress and have this rules now:

<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)

If you change the url part of /apartamento/t2-2-quartos/venda/usado/guia-albufeira-faro/ it will take you to the same url. 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

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

It points to the same place

Upvotes: 1

Views: 656

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

To redirect

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

to

  • /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]

Upvotes: 1

Related Questions