You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Sharjeel Tariq <sh...@gmail.com> on 2009/10/01 17:53:15 UTC

[users@httpd] apache redirection does not work

Hi,


I am trying to set up apache redirection rule for redirecting all of our non
'www' domains to 'www' domains. I got the redirection rule from apache
manual
but the rule does not work when we have subdirectories and parameters at the
end of url.

The redirection rule i have is


RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]


The above rule works for all urls except when I have urls like

http://example.com/news/headlines/more.jsp?content=20090624_075115_6540

Instead of redirecting the above url to

http://www.example.com/news/headlines/more.jsp?content=20090624_075115_6540

It is redirecting it to home page of site with
"?content=20090624_075115_6540" at the end


http://www.example.com/index.jsp?content=20090624_075115_6540

I need a generic redirection rule to redirection all non 'www' urls to 'www'
urls. I have to apply this rule on almost 50 web sites.


Thanks,

Re: [users@httpd] apache redirection does not work

Posted by Eric Covener <co...@gmail.com>.
On Fri, Oct 2, 2009 at 4:07 PM, Sharjeel Tariq
<sh...@gmail.com> wrote:
>  the redirection rule is written in a separate file under <VirtualHost *>.
>
>
> RewriteCond %{HTTP_HOST} ^example.com$
> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]
>
>
> The issue was that above rule works for all urls except for urls like
> http://example.com/news/headlines/more.jsp?content=20090624_075115_6540
>
>
> the rule redirects the above url to home page of site
>
> http://www.example.com/index.jsp?content=20090624_075115_6540

And it can't be captured by a RewriteLog?  Is it some other
rewrite/redirect occuring?

-- 
Eric Covener
covener@gmail.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] apache redirection does not work

Posted by Sharjeel Tariq <sh...@gmail.com>.
 the redirection rule is written in a separate file under <VirtualHost *>.


RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]


The issue was that above rule works for all urls except for urls like
http://example.com/news/headlines/more.jsp?content=20090624_075115_6540


the rule redirects the above url to home page of site

http://www.example.com/index.jsp?content=20090624_075115_6540


Thanks,
Sharjeel.

On Fri, Oct 2, 2009 at 3:59 PM, Eric Covener <co...@gmail.com> wrote:

> On Fri, Oct 2, 2009 at 3:48 PM, Sharjeel Tariq
> <sh...@gmail.com> wrote:
> > rewriteEngine is on. Here is the rule in Virtual Host.
> >
> > <VirtualHost *>
> >      Servername www.example.com
> >      DocumentRoot /www/www_example_com/
> >                  CustomLog /var/log/apache/www_example_com_access.log
> > combined env=!disable_logging
> >                  ErrorLog /var/log/apache/www_example_com_error.log
> >                  include conf/shared/blockWebInf.inc
> >                  CookieDomain .example.com
> >                  WLCookieName visunique
> >                  CookieTracking on
> >      RewriteEngine On
> >      RewriteRule ^/(.*\.jsp.*$|.*\/$|$)
> > http://localhost:6201/www_example_com/$1 [P]
> >      ProxyPassReverse / http://localhost:6201/www_example_com
> > </VirtualHost>
> >
> >
> > Can I say this is a bug in apache as I got this redirction rule from
> apache
> > manual to redirect all non 'www' requests to 'www' requests but it seems
> as
> > apache is not handling the urls with parameter at the end?
>
> Did you paste the right snippet? That's a pretty elaborate regex, and
> doesn't redirect at all but proxies.
>
> --
> Eric Covener
> covener@gmail.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] apache redirection does not work

Posted by Eric Covener <co...@gmail.com>.
On Fri, Oct 2, 2009 at 3:48 PM, Sharjeel Tariq
<sh...@gmail.com> wrote:
> rewriteEngine is on. Here is the rule in Virtual Host.
>
> <VirtualHost *>
>      Servername www.example.com
>      DocumentRoot /www/www_example_com/
>                  CustomLog /var/log/apache/www_example_com_access.log
> combined env=!disable_logging
>                  ErrorLog /var/log/apache/www_example_com_error.log
>                  include conf/shared/blockWebInf.inc
>                  CookieDomain .example.com
>                  WLCookieName visunique
>                  CookieTracking on
>      RewriteEngine On
>      RewriteRule ^/(.*\.jsp.*$|.*\/$|$)
> http://localhost:6201/www_example_com/$1 [P]
>      ProxyPassReverse / http://localhost:6201/www_example_com
> </VirtualHost>
>
>
> Can I say this is a bug in apache as I got this redirction rule from apache
> manual to redirect all non 'www' requests to 'www' requests but it seems as
> apache is not handling the urls with parameter at the end?

Did you paste the right snippet? That's a pretty elaborate regex, and
doesn't redirect at all but proxies.

-- 
Eric Covener
covener@gmail.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] apache redirection does not work

Posted by Sharjeel Tariq <sh...@gmail.com>.
rewriteEngine is on. Here is the rule in Virtual Host.

<VirtualHost *>
     Servername www.example.com
     DocumentRoot /www/www_example_com/
                 CustomLog /var/log/apache/www_example_com_access.log
combined env=!disable_logging
                 ErrorLog /var/log/apache/www_example_com_error.log
                 include conf/shared/blockWebInf.inc
                 CookieDomain .example.com
                 WLCookieName visunique
                 CookieTracking on
     RewriteEngine On
     RewriteRule ^/(.*\.jsp.*$|.*\/$|$)
http://localhost:6201/www_example_com/$1 [P]
     ProxyPassReverse / http://localhost:6201/www_example_com
</VirtualHost>


Can I say this is a bug in apache as I got this redirction rule from apache
manual to redirect all non 'www' requests to 'www' requests but it seems as
apache is not handling the urls with parameter at the end?



On Fri, Oct 2, 2009 at 11:23 AM, Eric Covener <co...@gmail.com> wrote:

> On Fri, Oct 2, 2009 at 10:46 AM, Sharjeel Tariq
> <sh...@gmail.com> wrote:
> > The issue with creating ServerAlias is we get two analytics reports for
> each
> > of our site. There are many benefits associated with redirecting non
> 'www'
> > urls to 'www' urls.
> >
> > I tried using following configuration in httpd.conf as per Bob
> > recommendation.
> >
> >
> > Rewritelog logs/rewrite_log
> > Rewriteloglevel 6
> >
> >
> > It created file rewrite_log but did not write any thing in the log file.
> I
> > have also tried using QSA flag to the rule but that didn't work either.
>
> no RewriteEngine on, htaccess not being read (allowoverride?), or
> rules in a  <virtualHost> that isn't actually handling the request?
>
> --
> Eric Covener
> covener@gmail.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] apache redirection does not work

Posted by Eric Covener <co...@gmail.com>.
On Fri, Oct 2, 2009 at 10:46 AM, Sharjeel Tariq
<sh...@gmail.com> wrote:
> The issue with creating ServerAlias is we get two analytics reports for each
> of our site. There are many benefits associated with redirecting non 'www'
> urls to 'www' urls.
>
> I tried using following configuration in httpd.conf as per Bob
> recommendation.
>
>
> Rewritelog logs/rewrite_log
> Rewriteloglevel 6
>
>
> It created file rewrite_log but did not write any thing in the log file. I
> have also tried using QSA flag to the rule but that didn't work either.

no RewriteEngine on, htaccess not being read (allowoverride?), or
rules in a  <virtualHost> that isn't actually handling the request?

-- 
Eric Covener
covener@gmail.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] apache redirection does not work

Posted by Sharjeel Tariq <sh...@gmail.com>.
The issue with creating ServerAlias is we get two analytics reports for each
of our site. There are many benefits associated with redirecting non 'www'
urls to 'www' urls.

I tried using following configuration in httpd.conf as per Bob
recommendation.


Rewritelog logs/rewrite_log
Rewriteloglevel 6


It created file rewrite_log but did not write any thing in the log file. I
have also tried using QSA flag to the rule but that didn't work either.


Thanks,
Sharjeel

On Thu, Oct 1, 2009 at 5:06 PM, Martin Spinassi <ma...@gmail.com>wrote:

> On Thu, 2009-10-01 at 11:53 -0400, Sharjeel Tariq wrote:
> > Hi,
> >
> >
> > I am trying to set up apache redirection rule for redirecting all of
> > our non
> > 'www' domains to 'www' domains. I got the redirection rule from apache
> > manual
> > but the rule does not work when we have subdirectories and parameters
> > at the
> > end of url.
> >
> > The redirection rule i have is
> >
> >
> > RewriteCond %{HTTP_HOST} ^example.com$
> > RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]
> >
> <snip>
>
> Sharjeel,
>
> I know it's not what you are asking for, but may accomplish your task.
>
> You can try adding a ServerAlias to the VirtualHost:
>
> ServerName example.com
> ServerAlias www.example.com
>
> Here is the documentation at apache site:
> http://httpd.apache.org/docs/2.0/mod/core.html#serveralias
>
>
> Sorry if it's not what you are asking for, but it's pretty much waht I'd
> do. With a simple script you can manage to add the ServerAlias to all
> the VirtualHosts.
>
>
> Cheers,
>
> Martin
>
>
> ---------------------------------------------------------------------
> 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] apache redirection does not work

Posted by Martin Spinassi <ma...@gmail.com>.
On Thu, 2009-10-01 at 11:53 -0400, Sharjeel Tariq wrote:
> Hi,
> 
> 
> I am trying to set up apache redirection rule for redirecting all of
> our non
> 'www' domains to 'www' domains. I got the redirection rule from apache
> manual
> but the rule does not work when we have subdirectories and parameters
> at the
> end of url.
> 
> The redirection rule i have is 
> 
> 
> RewriteCond %{HTTP_HOST} ^example.com$
> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]
> 
<snip>

Sharjeel,

I know it's not what you are asking for, but may accomplish your task.

You can try adding a ServerAlias to the VirtualHost:

ServerName example.com
ServerAlias www.example.com

Here is the documentation at apache site:
http://httpd.apache.org/docs/2.0/mod/core.html#serveralias


Sorry if it's not what you are asking for, but it's pretty much waht I'd
do. With a simple script you can manage to add the ServerAlias to all
the VirtualHosts.


Cheers,

Martin


---------------------------------------------------------------------
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] apache redirection does not work

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Thu, Oct 1, 2009 at 9:37 AM, Bob Ionescu <bo...@googlemail.com> wrote:
> 2009/10/1 Sharjeel Tariq <sh...@gmail.com>:
>> RewriteCond %{HTTP_HOST} ^example.com$
>> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]
>>
>>
>> The above rule works for all urls except when I have urls like
>>
>> http://example.com/news/headlines/more.jsp?content=20090624_075115_6540
>>
>> Instead of redirecting the above url to
>>
>> http://www.example.com/news/headlines/more.jsp?content=20090624_075115_6540
>>
>> It is redirecting it to home page of site with
>> "?content=20090624_075115_6540" at the end
>>
>>
>> http://www.example.com/index.jsp?content=20090624_075115_6540
>
> Please enable a RewriteLog with
>
> Rewritelog logs/rewrite_log
> Rewriteloglevel 6
>
> in your httpd.conf and post the result (may be as an attachment).
>
> Bob
>
> ---------------------------------------------------------------------
> 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
>
>

Try adding QSA to the flags at the end of the redirect.  (Query-String All)

---------------------------------------------------------------------
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] apache redirection does not work

Posted by Bob Ionescu <bo...@googlemail.com>.
2009/10/1 Sharjeel Tariq <sh...@gmail.com>:
> RewriteCond %{HTTP_HOST} ^example.com$
> RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R]
>
>
> The above rule works for all urls except when I have urls like
>
> http://example.com/news/headlines/more.jsp?content=20090624_075115_6540
>
> Instead of redirecting the above url to
>
> http://www.example.com/news/headlines/more.jsp?content=20090624_075115_6540
>
> It is redirecting it to home page of site with
> "?content=20090624_075115_6540" at the end
>
>
> http://www.example.com/index.jsp?content=20090624_075115_6540

Please enable a RewriteLog with

Rewritelog logs/rewrite_log
Rewriteloglevel 6

in your httpd.conf and post the result (may be as an attachment).

Bob

---------------------------------------------------------------------
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