lucy24

msg:4341062 | 3:36 am on Jul 19, 2011 (gmt 0) |
To clarify: Just this one directory? Not everything else in the domain? The line RewriteCond %{HTTP_HOST} . is not necessary. There is always a host. Do you have two entirely separate domains, example.com and www.example.com, each with a /map/ directory? This does not seem likely. And if you don't, there is no point to putting the htaccess in the /map/ directory, because requests have either already asked for the correct domain, or they will never see the htaccess. Is there a reason for redirecting only the requests for this directory? If not, you can save yourself a lot of hair-pulling by looking at your host's fine print. They may already have an option for directing everything to either www. or not-www. if you click the right button. No reason to mess with htaccess if you don't have to.
|
g1smd

msg:4341125 | 8:02 am on Jul 19, 2011 (gmt 0) |
There isn't if it is a HTTP/1.0 request. That's why the oft-quoted RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$ pattern is used (and it parses faster than two separate conditions). Additionally, with no end tag on the pattern, the rule would fail to redirect requests for www.example.com:80 to the canonical URL.
HTTP_HOST can match ONLY the requested host name and server port. It cannot see protocol, path or query string data.
|
akreider

msg:4341296 | 4:58 pm on Jul 19, 2011 (gmt 0) |
Lucy - the person is in the right directory. I'm redirecting non-www to www for that directory. g1smd - how do I get that pattern to work with a directory?
|
akreider

msg:4341314 | 5:34 pm on Jul 19, 2011 (gmt 0) |
I got it to work with a php rewrite. If "www" isn't in the HTTP_HOST, I have javascript change the url using window.location.href to [domain.org...] + $_SERVER['PHP_SELF']+$_SERVER['QUERY_STRING']
|
g1smd

msg:4341462 | 11:01 pm on Jul 19, 2011 (gmt 0) |
Your javascript rule will not issue the 301 redirect the searchengines need to see. You MUST use the HEADER function in PHP or else a RewriteRule in the .htaccess file. The RewriteRule pattern matches the path part of the URL as long as you use the correct pattern for the Regular Expression. You only need a preceding RewriteCond when you want to look at SERVER_PORT, HTTP_HOST, QUERY_STRING, and many other things that are not the PATH part of the URL request.
|
|