You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Andoni <an...@eurokom.ie> on 2005/10/21 20:12:12 UTC

[users@httpd] Should be easy RewriteRule issue: mod_rewrite.

Hi,

Can you please help me with this RewriteRule. I am trying to all users of my website to type in:

www.mysite.com/area1

and have it re-written to:

www.mysite.com/servMainSite?inner=area1

The slight complication is that /img, /css and /menu have to work as of course does /servMainSite. At the moment I am getting an infinite loop with the following:

#  RewriteRule !^/(servMainSite.*|img.*|css.*|menu.*)/ /servMainSite?inner=$1 [R,L]


Hope you can help.

Andoni.

[users@httpd] Re: Re: Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Andoni <an...@eurokom.ie>.
Hi,

Found the problem. The PT worked. I think it's because I am forwarding everything to my Tomcat server using JkMount. This must be a form of Alias?

Anyway all working now. Thanks,

Andoni.
  ----- Original Message ----- 
  From: Joshua Slive 
  Newsgroups: gmane.comp.apache.user
  Sent: Monday, October 24, 2005 4:38 PM
  Subject: Re: Re: Re: Should be easy RewriteRule issue: mod_rewrite.


  On 10/24/05, Andoni <an...@eurokom.ie> wrote:
  >
  > Hi,
  >
  > Removing the "R" broke it :-(
  >
  > Now when I go to www.mydomain.com/frontpage it does not re-write it at all,
  > just giving me back a "page cannot be found" instead.

  Then you need to use the RewriteLog to figure out what is going on. 
  One possibility is to add the PT flag to the RewriteRule, which is
  necessary if the URL will go through further aliasing.

  Joshua.

  ---------------------------------------------------------------------
  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] Re: Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Joshua Slive <js...@gmail.com>.
On 10/24/05, Andoni <an...@eurokom.ie> wrote:
>
> Hi,
>
> Removing the "R" broke it :-(
>
> Now when I go to www.mydomain.com/frontpage it does not re-write it at all,
> just giving me back a "page cannot be found" instead.

Then you need to use the RewriteLog to figure out what is going on. 
One possibility is to add the PT flag to the RewriteRule, which is
necessary if the URL will go through further aliasing.

Joshua.

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


[users@httpd] Re: Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Andoni <an...@eurokom.ie>.
Hi,

Removing the "R" broke it :-(

Now when I go to www.mydomain.com/frontpage it does not re-write it at all, just giving me back a "page cannot be found" instead.

Andoni.
  ----- Original Message ----- 
  From: Joshua Slive 
  Newsgroups: gmane.comp.apache.user
  Sent: Monday, October 24, 2005 3:23 PM
  Subject: Re: Re: Should be easy RewriteRule issue: mod_rewrite.


  On 10/24/05, Andoni <an...@eurokom.ie> wrote:
  >
  > Now why could the documentation not have said that?

  The two types of redirect are discussed at
  http://httpd.apache.org/docs/2.0/urlmapping.html

  It is assumed that you wouldn't possibly dare trying to read the
  mod_rewrite docs unless you are already a url-guru ;-)

  Seriously, there is a "rewrite" of the mod_rewrite docs underway at
  http://httpd.apache.org/docs/2.0/rewrite/
  but it is kind of stalled.

  Joshua.

  ---------------------------------------------------------------------
  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] Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Joshua Slive <js...@gmail.com>.
On 10/24/05, Andoni <an...@eurokom.ie> wrote:
>
> Now why could the documentation not have said that?

The two types of redirect are discussed at
http://httpd.apache.org/docs/2.0/urlmapping.html

It is assumed that you wouldn't possibly dare trying to read the
mod_rewrite docs unless you are already a url-guru ;-)

Seriously, there is a "rewrite" of the mod_rewrite docs underway at
http://httpd.apache.org/docs/2.0/rewrite/
but it is kind of stalled.

Joshua.

---------------------------------------------------------------------
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] Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Andoni <an...@eurokom.ie>.
Now why could the documentation not have said that?

You have no idea what that means to me! I am about to go and re-write several of the Virtual Hosts on my web-server to use that content redirection.

My thanks,

Andoni.
  ----- Original Message ----- 
  From: Joshua Slive 
  To: users@httpd.apache.org 
  Sent: Monday, October 24, 2005 2:37 PM
  Subject: Re: [users@httpd] Re: Should be easy RewriteRule issue: mod_rewrite.


  On 10/24/05, Andoni <an...@eurokom.ie> wrote:
  >
  > Hi Joshua (and all),
  >
  > That worked great thanks, I had to take out the caret ^ you had at the
  > beginning of /servMainSite in the RewriteRule to make it work but otherwise
  > fine.

  Yes, that was a typo on my part.


  >   RewriteRule ^/(.*)$ /servMainSite?inner=$1 [R,QSA,L]
  >
  > I also added the R flag. Mainly because I always have done and it has always
  > worked for me! The documentation is so confusing though, can you tell me if
  > it is necessary? When I look at the RewriteLog I find that it has now got a
  > 302 is this what I want? Should I add a "permanent" flag?

  The R indicates an external redirect, meaning the client is asked to
  refetch the resource at the new location (and you'll notice a change
  in the client's URL-bar).  If you omit the R (which I would recommend
  in this case), the server will fetch the content at the new location
  and return it to the client as if it was at the old location.

  Joshua.

  ---------------------------------------------------------------------
  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] Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Joshua Slive <js...@gmail.com>.
On 10/24/05, Andoni <an...@eurokom.ie> wrote:
>
> Hi Joshua (and all),
>
> That worked great thanks, I had to take out the caret ^ you had at the
> beginning of /servMainSite in the RewriteRule to make it work but otherwise
> fine.

Yes, that was a typo on my part.


>   RewriteRule ^/(.*)$ /servMainSite?inner=$1 [R,QSA,L]
>
> I also added the R flag. Mainly because I always have done and it has always
> worked for me! The documentation is so confusing though, can you tell me if
> it is necessary? When I look at the RewriteLog I find that it has now got a
> 302 is this what I want? Should I add a "permanent" flag?

The R indicates an external redirect, meaning the client is asked to
refetch the resource at the new location (and you'll notice a change
in the client's URL-bar).  If you omit the R (which I would recommend
in this case), the server will fetch the content at the new location
and return it to the client as if it was at the old location.

Joshua.

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


[users@httpd] Re: Should be easy RewriteRule issue: mod_rewrite.

Posted by Andoni <an...@eurokom.ie>.
Hi Joshua (and all),

That worked great thanks, I had to take out the caret ^ you had at the beginning of /servMainSite in the RewriteRule to make it work but otherwise fine. Here's what I ended up with:

  RewriteCond %{Request_URI} !^/img
  RewriteCond %{Request_URI} !^/favicon.ico
  RewriteCond %{Request_URI} !^/robots.txt
  RewriteCond %{Request_URI} !^/css
  RewriteCond %{Request_URI} !^/menu
  RewriteCond %{Request_URI} !^/servMainSite
  RewriteRule ^/(.*)$ /servMainSite?inner=$1 [R,QSA,L]

I also added the R flag. Mainly because I always have done and it has always worked for me! The documentation is so confusing though, can you tell me if it is necessary? When I look at the RewriteLog I find that it has now got a 302 is this what I want? Should I add a "permanent" flag?

Thanks,

Andoni
  ----- Original Message ----- 
  From: Joshua Slive 
  Newsgroups: gmane.comp.apache.user
  Sent: Friday, October 21, 2005 7:25 PM
  Subject: Re: Should be easy RewriteRule issue: mod_rewrite.


  On 10/21/05, Andoni <an...@eurokom.ie> wrote:
  > Can you please help me with this RewriteRule. I am trying to all users of my
  > website to type in:
  >
  > www.mysite.com/area1
  >
  > and have it re-written to:
  >
  > www.mysite.com/servMainSite?inner=area1
  >
  > The slight complication is that /img, /css and /menu have to work as of
  > course does /servMainSite. At the moment I am getting an infinite loop with
  > the following:
  >
  > #  RewriteRule !^/(servMainSite.*|img.*|css.*|menu.*)/
  > /servMainSite?inner=$1 [R,L]

  There are several ways to do this.  Here's one:

  RewriteEngine On
  RewriteCond %{Request_URI} !^/img
  RewriteCond %{Request_URI} !^/css
  ...
  RewriteRule ^/(.*) ^/servMainSite?inner=$1 [QSA,L]

  Joshua.

  ---------------------------------------------------------------------
  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] Should be easy RewriteRule issue: mod_rewrite.

Posted by Joshua Slive <js...@gmail.com>.
On 10/21/05, Andoni <an...@eurokom.ie> wrote:
> Can you please help me with this RewriteRule. I am trying to all users of my
> website to type in:
>
> www.mysite.com/area1
>
> and have it re-written to:
>
> www.mysite.com/servMainSite?inner=area1
>
> The slight complication is that /img, /css and /menu have to work as of
> course does /servMainSite. At the moment I am getting an infinite loop with
> the following:
>
> #  RewriteRule !^/(servMainSite.*|img.*|css.*|menu.*)/
> /servMainSite?inner=$1 [R,L]

There are several ways to do this.  Here's one:

RewriteEngine On
RewriteCond %{Request_URI} !^/img
RewriteCond %{Request_URI} !^/css
...
RewriteRule ^/(.*) ^/servMainSite?inner=$1 [QSA,L]

Joshua.

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