search

Home  >  Q&A  >  body text

How to rewrite URL in .htaccess when URL does not end with language ID or country ID

How to rewrite URL in .htaccess if it does not end with language ID or country ID

In my case I want the redirect link not to end with

home/(en | fr| ar)/(us| ma |ae | sa )

For example:

https://exemple.com/home/en/sa/...

https://exemple.com/home/es/sa/...

https://exemple.com/home/ar/...

I tried this:

RewriteRule ^home/!(en|ae|sa)/!(sa|ma|ae|sa)/(.*)$ / [L,R=301,QSA]

But it didn't work

thank you all

P粉005105443P粉005105443319 days ago465

reply all(1)I'll reply

  • P粉211273535

    P粉2112735352024-01-17 16:39:40

    You can use the following redirect rules:

    RewriteRule ^home/(?!(?:en|fr|ar)/(?:us|ma|ae|sa))([^/]+/[^/]+) / [L,R=301,NC,NE]
    

    (?!(?:en|fr|ar)/(?:us|ma|ae|sa)) is a negative lookahead condition if /home If it is not followed by the allowed language/country code, the match will fail.

    reply
    0
  • Cancelreply