Question

I have been reading the Rewrite condition info in the Apache documentation but have got nowhere, so I hope you can help. In my .htaccess file I had some lines that ran thus:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^mydomain.com [nc]
rewriterule ^(.*)$ http://www.mydomain.com/$1 [r=301,nc]

I have since noticed that a dollar sign was missing from line 3, so it should have run thus:

rewritecond %{http_host} ^mydomain.com$ [nc]

So my question has two parts, was it working (doing anything) originally (and what??)? And if not, how was it interpreted with the missing '$'. Thank you.

Was it helpful?

Solution

Your question says ? but probably mean missing anchor $ from your regex.

rewritecond %{http_host} ^mydomain.com$ [nc]

Even more correct would be:

rewritecond %{http_host} ^mydomain\.com$ [nc]

Since dot can mean anything in regex and literal dot needs to be escaped.

Without $ also it might work but in theory it can match mydomain.comp also. With $ in place it can only match mydomain.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top