Q about mod_rewrite flags

Q about mod_rewrite flags

am 19.01.2008 11:20:10 von Jason Carlton

I thought that I understood flags, but I guess not!

My site has a series of parked domains, and based on what domain is
typed in, the visitor sees different verbiage. However, a few bugs
have been that if they leave off the www or trailing slash, they're
redirected to the primary domain, seeing the wrong information.

To combat this, I'm using the following recipe in .htaccess:

RewriteEngine On
RewriteOptions MaxRedirects=2

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [QSA]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]

This works well, but not perfectly. It doesn't actually change the
address in the bar, so even though the page itself is found, images
and scripts that are loaded relatively don't load. I'm guessing that
the server still thinks that the page without the trailing slash is a
directory (it's just being tricked into showing a page), so the ../../
looks back one directory too far.

What flag would force the address to physically change? So if they
typed in http://mydomain.com/directory , the address bar would
automatically change to http://www.mydomain.com/directory/ ?

FYI, I read through the manual twice, but didn't see this answer. But
I'm sure that I've seen it discussed before on here, so I'm sure that
I'm just overlooking it.

TIA,

Jason

Re: Q about mod_rewrite flags

am 21.01.2008 15:44:44 von Trammel

"Jason Carlton" wrote in message
news:1848bc26-7244-4378-acd9-f2b7b1596054@k2g2000hse.googleg roups.com...
>I thought that I understood flags, but I guess not!
>
> My site has a series of parked domains, and based on what domain is
> typed in, the visitor sees different verbiage. However, a few bugs
> have been that if they leave off the www or trailing slash, they're
> redirected to the primary domain, seeing the wrong information.
>
> To combat this, I'm using the following recipe in .htaccess:
>
> RewriteEngine On
> RewriteOptions MaxRedirects=2
>
> RewriteCond %{REQUEST_FILENAME} -d
> RewriteRule ^(.+[^/])$ $1/ [QSA]
>
> RewriteCond %{HTTP_HOST} !^www\.
> RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
>
> This works well, but not perfectly. It doesn't actually change the
> address in the bar, so even though the page itself is found, images
> and scripts that are loaded relatively don't load. I'm guessing that
> the server still thinks that the page without the trailing slash is a
> directory (it's just being tricked into showing a page), so the ../../
> looks back one directory too far.
>
> What flag would force the address to physically change? So if they
> typed in http://mydomain.com/directory , the address bar would
> automatically change to http://www.mydomain.com/directory/ ?
>
> FYI, I read through the manual twice, but didn't see this answer. But
> I'm sure that I've seen it discussed before on here, so I'm sure that
> I'm just overlooking it.
>
> TIA,
>
> Jason

Im new to mod_rewrite (I've only edited one from an example) but try here:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

This info contained in it looks like what your after:
'redirect|R [=code]' (force redirect)
Prefix Substitution with http://thishost[:thisport]/ (which makes the new
URL a URI) to force a external redirection. If no code is given, a HTTP
response of 302 (MOVED TEMPORARILY) will be returned. If you want to use
other response codes in the range 300-400, simply specify the appropriate
number or use one of the following symbolic names: temp (default),
permanent, seeother. Use this for rules to canonicalize the URL and return
it to the client - to translate ``/~'' into ``/u/'', or to always append a
slash to /u/user, etc.
Note: When you use this flag, make sure that the substitution field is a
valid URL! Otherwise, you will be redirecting to an invalid location.
Remember that this flag on its own will only prepend
http://thishost[:thisport]/ to the URL, and rewriting will continue.
Usually, you will want to stop rewriting at this point, and redirect
immediately. To stop rewriting, you should add the 'L' flag.