You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Drew Tomlinson <dr...@mykitchentable.net> on 2008/09/16 00:46:56 UTC
[users@httpd] Trouble With mod_rewrite
I'm using Apache version 2.2.6 with dynamic modules. I'm trying to use
mod_rewrite to change a URL. Specifically, if someone enters:
http://www.consumer-sc.ca.gov
I want to redirect him and make his browser window show:
http://www.consumerservices.ca.gov
Both domains resolve to the same IP address.
I've Googled and found many examples that describe this very exact
scenario but I have been unable to make it work. Specifically, I've
added these lines to my conf file:
# Added Rewrite rule to change consumer-sc.ca.gov consumerservices.ca.gov
# Taken from example at
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.consumerservices.ca.gov/$1 [L,R=301]
After restarting the web server, connections to
http://www.consumer-sc.ca.gov do not get rewritten. The page is served
exactly as if there was no mod_rewrite.
Connections to http://www.consumerservices.ca.gov receive a "Moved
Permanently - The document has moved here." message with "here" being a
link to http://www.consumerservices.ca.gov.
I'm sure I'm missing something simple. Would someone please hit me with
a clue stick?
Thanks,
Drew
--
Be a Great Magician!
Visit The Alchemist's Warehouse
http://www.alchemistswarehouse.com
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Trouble With mod_rewrite
Posted by Tom Evans <te...@googlemail.com>.
On Tue, 2008-09-16 at 07:01 -0700, Drew Tomlinson wrote:
> Ben Spencer wrote:
> > Looks like you went the wrong direction with the rewrite. The ! is "not".
> > You have "not" www.consumer-sc.ca.gov, then redirect.
> >
> > RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
> >
> > Should be
> >
> > RewriteCond %{HTTP_HOST} ^www\.consumer-sc\.ca\.gov$ [NC]
> >
> > Or even (which doesn't force the requirement of "www")
> >
> > RewriteCond %{HTTP_HOST} consumer-sc\.ca\.gov$ [NC]
> >
>
> Thank you very much! That was it.
>
> Drew
>
Whilst that is absolutely correct, I think the 'correct' (nothing is
ever correct) logic is that you wish all requests to be served from (eg)
www.mainsite.com, rather than sub.mainsite.com or mainsite.com (or any
other ServerAlias). Hence, I'd write the rule as:
RewriteCond %{HTTP_HOST} !^www\.mainsite\.com$ [NC]
RewriteRule ^/(.*) http://www.mainsite.com/$1 [R=301,L]
Cheers
Tom
Re: [users@httpd] Trouble With mod_rewrite
Posted by Drew Tomlinson <dr...@mykitchentable.net>.
Ben Spencer wrote:
> Looks like you went the wrong direction with the rewrite. The ! is "not".
> You have "not" www.consumer-sc.ca.gov, then redirect.
>
> RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
>
> Should be
>
> RewriteCond %{HTTP_HOST} ^www\.consumer-sc\.ca\.gov$ [NC]
>
> Or even (which doesn't force the requirement of "www")
>
> RewriteCond %{HTTP_HOST} consumer-sc\.ca\.gov$ [NC]
>
Thank you very much! That was it.
Drew
--
Be a Great Magician!
Visit The Alchemist's Warehouse
http://www.alchemistswarehouse.com
>> -----Original Message-----
>> From: Drew Tomlinson [mailto:drew@mykitchentable.net]
>> Sent: Monday, September 15, 2008 5:47 PM
>> To: users@httpd.apache.org
>> Subject: [users@httpd] Trouble With mod_rewrite
>>
>> I'm using Apache version 2.2.6 with dynamic modules. I'm trying to use
>> mod_rewrite to change a URL. Specifically, if someone enters:
>>
>> http://www.consumer-sc.ca.gov
>>
>> I want to redirect him and make his browser window show:
>>
>> http://www.consumerservices.ca.gov
>>
>> Both domains resolve to the same IP address.
>>
>> I've Googled and found many examples that describe this very exact
>> scenario but I have been unable to make it work. Specifically, I've
>> added these lines to my conf file:
>>
>> # Added Rewrite rule to change consumer-sc.ca.gov
>> consumerservices.ca.gov
>> # Taken from example at
>> http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
>> RewriteEngine on
>> RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
>> RewriteCond %{HTTP_HOST} !^$
>> RewriteRule ^/(.*) http://www.consumerservices.ca.gov/$1
>> [L,R=301]
>>
>> After restarting the web server, connections to
>> http://www.consumer-sc.ca.gov do not get rewritten. The page is served
>> exactly as if there was no mod_rewrite.
>>
>> Connections to http://www.consumerservices.ca.gov receive a "Moved
>> Permanently - The document has moved here." message with "here" being a
>> link to http://www.consumerservices.ca.gov.
>>
>> I'm sure I'm missing something simple. Would someone please hit me
>> with
>> a clue stick?
>>
>> Thanks,
>>
>> Drew
>>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
RE: [users@httpd] Trouble With mod_rewrite
Posted by Ben Spencer <be...@moody.edu>.
Looks like you went the wrong direction with the rewrite. The ! is "not".
You have "not" www.consumer-sc.ca.gov, then redirect.
RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
Should be
RewriteCond %{HTTP_HOST} ^www\.consumer-sc\.ca\.gov$ [NC]
Or even (which doesn't force the requirement of "www")
RewriteCond %{HTTP_HOST} consumer-sc\.ca\.gov$ [NC]
benji
Benji Spencer
System Administrator
Moody Bible Institute
Phone: 312-329-2288
Fax: 312-329-8961
> -----Original Message-----
> From: Drew Tomlinson [mailto:drew@mykitchentable.net]
> Sent: Monday, September 15, 2008 5:47 PM
> To: users@httpd.apache.org
> Subject: [users@httpd] Trouble With mod_rewrite
>
> I'm using Apache version 2.2.6 with dynamic modules. I'm trying to use
> mod_rewrite to change a URL. Specifically, if someone enters:
>
> http://www.consumer-sc.ca.gov
>
> I want to redirect him and make his browser window show:
>
> http://www.consumerservices.ca.gov
>
> Both domains resolve to the same IP address.
>
> I've Googled and found many examples that describe this very exact
> scenario but I have been unable to make it work. Specifically, I've
> added these lines to my conf file:
>
> # Added Rewrite rule to change consumer-sc.ca.gov
> consumerservices.ca.gov
> # Taken from example at
> http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
> RewriteEngine on
> RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
> RewriteCond %{HTTP_HOST} !^$
> RewriteRule ^/(.*) http://www.consumerservices.ca.gov/$1
> [L,R=301]
>
> After restarting the web server, connections to
> http://www.consumer-sc.ca.gov do not get rewritten. The page is served
> exactly as if there was no mod_rewrite.
>
> Connections to http://www.consumerservices.ca.gov receive a "Moved
> Permanently - The document has moved here." message with "here" being a
> link to http://www.consumerservices.ca.gov.
>
> I'm sure I'm missing something simple. Would someone please hit me
> with
> a clue stick?
>
> Thanks,
>
> Drew
>
> --
> Be a Great Magician!
> Visit The Alchemist's Warehouse
>
> http://www.alchemistswarehouse.com
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Trouble With mod_rewrite
Posted by Dan Poirier <po...@pobox.com>.
In the first RewriteCond, you want to match www.consumer-sc.ca.gov, but
the ! in front says to match anything but that. That's also why
consumerservices.ca.gov is returning a 301, because it does match the
condition.
On Mon, September 15, 2008 6:46 pm, Drew Tomlinson wrote:
> I'm using Apache version 2.2.6 with dynamic modules. I'm trying to use
> mod_rewrite to change a URL. Specifically, if someone enters:
>
> http://www.consumer-sc.ca.gov
>
> I want to redirect him and make his browser window show:
>
> http://www.consumerservices.ca.gov
>
> Both domains resolve to the same IP address.
>
> I've Googled and found many examples that describe this very exact
> scenario but I have been unable to make it work. Specifically, I've
> added these lines to my conf file:
>
> # Added Rewrite rule to change consumer-sc.ca.gov consumerservices.ca.gov
> # Taken from example at
> http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
> RewriteEngine on
> RewriteCond %{HTTP_HOST} !^www\.consumer-sc\.ca\.gov$ [NC]
> RewriteCond %{HTTP_HOST} !^$
> RewriteRule ^/(.*) http://www.consumerservices.ca.gov/$1 [L,R=301]
>
> After restarting the web server, connections to
> http://www.consumer-sc.ca.gov do not get rewritten. The page is served
> exactly as if there was no mod_rewrite.
>
> Connections to http://www.consumerservices.ca.gov receive a "Moved
> Permanently - The document has moved here." message with "here" being a
> link to http://www.consumerservices.ca.gov.
>
> I'm sure I'm missing something simple. Would someone please hit me with
> a clue stick?
>
> Thanks,
>
> Drew
>
> --
> Be a Great Magician!
> Visit The Alchemist's Warehouse
>
> http://www.alchemistswarehouse.com
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
--
Dan Poirier <po...@pobox.com>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org