You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Florent Georges <li...@fgeorges.org> on 2009/03/18 13:04:13 UTC

[users@httpd] mod_rewrite: moved directory

  Hi,

  I moved one directory one level up in the hierarchy of web pages,
let's say:

    from: http://www.example.com/parent/child/
    to:   http://www.example.com/child/

  I try to use mod_rewrite to handle this move, and redirect users
for a while to the new location.  I've read the URL Rewriting Guide
at <http://httpd.apache.org/docs/2.0/misc/rewriteguide.html>, from
which I thought the following should handle this case:

    RewriteEngine  on
    RewriteRule    ^/parent/child(.*) /child$1 [R]

  But it does not.  When I try to access the old location, I simlpy
get a 404.

  Is there a way to handle this problem?  With mod_rewrite or any
other "standard" module.

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/






















      

---------------------------------------------------------------------
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] mod_rewrite: moved directory

Posted by Brian Mearns <me...@gmail.com>.
On Wed, Mar 18, 2009 at 8:04 AM, Florent Georges <li...@fgeorges.org> wrote:
>
>  Hi,
>
>  I moved one directory one level up in the hierarchy of web pages,
> let's say:
>
>    from: http://www.example.com/parent/child/
>    to:   http://www.example.com/child/
>
>  I try to use mod_rewrite to handle this move, and redirect users
> for a while to the new location.  I've read the URL Rewriting Guide
> at <http://httpd.apache.org/docs/2.0/misc/rewriteguide.html>, from
> which I thought the following should handle this case:
>
>    RewriteEngine  on
>    RewriteRule    ^/parent/child(.*) /child$1 [R]
>
>  But it does not.  When I try to access the old location, I simlpy
> get a 404.
>
>  Is there a way to handle this problem?  With mod_rewrite or any
> other "standard" module.
>
>  Regards,
>
> --
> Florent Georges
> http://www.fgeorges.org/


Mod_rewrite is a perfectly good way to solve this problem. I'm not
sure off hand why it's not working, but your first step in debugging
this should be to turn on your rewrite logs and monitor them when you
try to access the old address. Check back in the documentation for how
to turn them on and where they live.

Once you resolve the issue, I would recommend using [R=301] instead of
just [R] for this rule, assuming that the move is permanent. This will
inform clients that from now on, they should use the new address
instead of continuing to use the old one, which will reduce connection
time and network traffic. A 301 will also help you if you're old pages
are known by any search engines because it will tell them that any
stats or ranking they've come up with for the old pages should be
transferred to the new ones, instead of starting from scratch.

Anyway, check your rewrite logs and if you're still having problems,
get back to us with the actual rewrite rule copied directly from your
config file: using phony urls (I'm assuming parent and child are
phony) is good for illustration, but not for debugging.

Hope that helps,
-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.edu/

---------------------------------------------------------------------
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] mod_rewrite: moved directory

Posted by Florent Georges <li...@fgeorges.org>.
Eric Covener wrote:

> If this is in .htaccess or <directory>, the RewriteBase is stripped
> from the URL before your rule compares to it -- it cannot start with
> a slash.

  Oops, I didn't mention that the rule was in an .htaccess, sorry.  Good guess!  Stripping the leading slash resolved the problem.  Thanks to both of you for your help.

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/























      

---------------------------------------------------------------------
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] mod_rewrite: moved directory

Posted by Eric Covener <co...@gmail.com>.
On Wed, Mar 18, 2009 at 8:04 AM, Florent Georges <li...@fgeorges.org> wrote:
>
>  Hi,
>
>  I moved one directory one level up in the hierarchy of web pages,
> let's say:
>
>    from: http://www.example.com/parent/child/
>    to:   http://www.example.com/child/
>
>  I try to use mod_rewrite to handle this move, and redirect users
> for a while to the new location.  I've read the URL Rewriting Guide
> at <http://httpd.apache.org/docs/2.0/misc/rewriteguide.html>, from
> which I thought the following should handle this case:
>
>    RewriteEngine  on
>    RewriteRule    ^/parent/child(.*) /child$1 [R]

If this is in .htaccess or <directory>, the RewriteBase is stripped
from the URL before your rule compares to it -- it cannot start with a
slash.
Also see AllowOverride.

A simple Alias might suffice too.

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