Reputation: 3677
I really tried everything, the tool htaccess tester says that it's ok, but it's not really working.
I want to redirect a subdomain to the main domain only if the REQUEST_URI doesn't start with 3 specific strings.
I tried without success with:
RewriteCond %{HTTP_HOST} ^sub.example.com$ [NC]
RewriteCond %{REQUEST_URI} !(aaa|bbb|ccc)
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI} [R=301,NC,L,QSA]
I want that:
http://sub.example.com
(shouldn't redirect) -> http://sub.example.com
| OKhttp://sub.example.com/aaa/sss
(shouldn't redirect) -> http://sub.example.com/aaa/sss
| KO (redirect to http://www...)http://sub.example.com/zzz/xxx
(should redirect) -> http://www.example.com/zzz/xxx
| OKThanks
Upvotes: 1
Views: 598
Reputation: 785276
Try this rule instead:
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} !\s/+(aaa|bbb|ccc)/ [NC]
RewriteRule . http://www.example.com%{REQUEST_URI} [R=301,L,NE]
Test it after clearing your browser cache.
Using THE_REQUEST
instead of REQUEST_URI
to make sure we use unchanged URI values as received by Apache.
Upvotes: 2