Reputation: 4343
I want to redirect my users to https if doesn't have "mob" suffix.
Example:
If url = http://example.com/(anything)/mob then don't redirect to https
If url = http://example.com/(anything) redirect to https
If url = http://example.com redirect to https
I tried following code but didn't work.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/(.*)/mob$
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 1
Views: 77
Reputation: 785098
Try this rule with THE_REQUEST
variable:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !/mob[/?\s] [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Make sure to test in a new browser or clear browser cache to avoid old cache.
Suggest you to keep this rule as your top rule.
Upvotes: 1