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粉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.