htaccess RewriteRule redirecting unexpectedly www

In my htaccess I have a rule -

I have this rule

RewriteRule ^mk$ http://mysite.com/mypage.php [r=301,nc]

and later on :

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

This works fine for http://mysite.com/mk - it redirects to: http://mysite.com/mypage.php as I wanted.

...but when I go to http://www.mysite.com/mk it redirects to http://mysite.com/http://mysite.com/mypage.php

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

Thanks

Answers


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 http://www.mysite.com/mk


Need Your Help

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

cookies asp.net-web-api oauth asp.net-web-api2

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