Htaccess redirect problem

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

solas,

It is merely TEXT which must be formatted correctly for the parser to interpret your wishes, Oh Mighty Master of Code. Unfortunately, they’ve yet to build an interpreter which can guess at the intent of the coder.

Okay, seriously, there are a large number of tutorials out there which can fill-in the blanks - see the linked “Article” in my signature for one built upon years in this forum answering the same questions over and over and … It’ll provide you with the syntax and a way to code properly.

Regards,

DK

The problem is that there is no [L] flag in the ^mk rule, but there should be. Also, since I’m assuming you don’t want ^mk to be case insensitive (i.e. also allow ^mK, ^MK, ^Mk etc), remove the [NC] from the first rule.

I’d also change


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

to


RewriteCond %{HTTP_HOST} !^mysite\\.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [L,R=301]

This version is a bit faster because it doesn’t use the evil .* - which matches nothing and everything.
Note that here you do need [NC] by the way, since users can type MySite.com in their browser; you have no control over that so the test should be case insensitive.

Brilliant, that worked a treat.

Why is htaccess stuff so hard… Is it a language in and of itself or is it based on something?