N
N
nadirq2015-07-23 15:58:14
htaccess
nadirq, 2015-07-23 15:58:14

What is the correct way to write a negated regex for .htaccess?

The site has different localizations for different countries. They look like this:
example.com/ar
example.com/es
example.com/it
example.com/ru
and 10 more pieces
You need to make a redirect for all locales, excluding two of them. That is, with / ar and / es redirect is not needed.
How do I do

RewriteCond %{REQUEST_URI} !(^/(ar|es))
RewriteRule .* http://example.com/some_page.html [R=302,L]

It doesn't work. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ShamblerR, 2015-07-24
@nadirq

In general, you are wrong, because with 10 sites it is really easier to make an inclusion than an exclusion by 3 letters, the probability of falling into this range is too high. Also, in the beginning, there is no slash in Uri, and therefore it does not work.
also don't forget about case insensitivity

RewriteCond %{REQUEST_URI} ^(it|ru|com|kz|ua) [NC]
RewriteRule ^.*$ http://%{SERVER_NAME}/some_page.html [R=301,L]

By the way, why do you need 302?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question