htaccess RewriteRule redirecting unexpectedly www

In my htaccess I have a rule -

I have this rule

RewriteRule ^mk$ [r=301,nc]

and later on :

RewriteCond %{HTTP_HOST} !^mysite\.com$ [NC]
RewriteRule ^(.*)$$1 [QSA,L,R=301]

This works fine for - it redirects to: as I wanted.

...but when I go to it redirects to

Are these 2 rules incompatable? Can anyone tell me what's happening and what to do?



They are compatible, but in your case I think order matters. I would move the host redirect above the mk redirect and try again.

Another thing would be to add the L flag (Last) to the mk rule. This should trigger the redirect immediately.

I am not sure if you have any other rules that you want to run first. So see what the order does if that matters to you. Essentially these rules are pairing up and double rewriting

Need Your Help

How do I combine OAuth and cookie authentication in Web API using OWIN?

cookies oauth

I have a ASP.NET Web API project that is an OAuth 2 authorization provider using OWIN. Once an OAuth access token expires, we want to fall back to cookie authentication to silently renew the token