Htaccess redirect problem

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?



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.



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 ^(.*)$$1 [QSA,L,R=301]


RewriteCond %{HTTP_HOST} !^mysite\\.com$ [NC]
RewriteRule .?{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 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?