mod_rewrite: moved directory

mod_rewrite: moved directory

am 18.03.2009 13:04:13 von Florent Georges

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

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



















=0A

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: mod_rewrite: moved directory

am 18.03.2009 13:55:26 von Brian Mearns

On Wed, Mar 18, 2009 at 8:04 AM, Florent Georges wrote=
:
>
> =A0Hi,
>
> =A0I moved one directory one level up in the hierarchy of web pages,
> let's say:
>
> =A0 =A0from: http://www.example.com/parent/child/
> =A0 =A0to: =A0 http://www.example.com/child/
>
> =A0I try to use mod_rewrite to handle this move, and redirect users
> for a while to the new location. =A0I've read the URL Rewriting Guide
> at , from
> which I thought the following should handle this case:
>
> =A0 =A0RewriteEngine =A0on
> =A0 =A0RewriteRule =A0 =A0^/parent/child(.*) /child$1 [R]
>
> =A0But it does not. =A0When I try to access the old location, I simlpy
> get a 404.
>
> =A0Is there a way to handle this problem? =A0With mod_rewrite or any
> other "standard" module.
>
> =A0Regards,
>
> --
> 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=3D301] 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

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

am 18.03.2009 14:01:46 von Eric Covener

On Wed, Mar 18, 2009 at 8:04 AM, Florent Georges wrote=
:
>
> =A0Hi,
>
> =A0I moved one directory one level up in the hierarchy of web pages,
> let's say:
>
> =A0 =A0from: http://www.example.com/parent/child/
> =A0 =A0to: =A0 http://www.example.com/child/
>
> =A0I try to use mod_rewrite to handle this move, and redirect users
> for a while to the new location. =A0I've read the URL Rewriting Guide
> at , from
> which I thought the following should handle this case:
>
> =A0 =A0RewriteEngine =A0on
> =A0 =A0RewriteRule =A0 =A0^/parent/child(.*) /child$1 [R]

If this is in .htaccess or , 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.

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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: mod_rewrite: moved directory

am 18.03.2009 14:17:52 von Florent Georges

Eric Covener wrote:

> If this is in .htaccess or , 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 gu=
ess! Stripping the leading slash resolved the problem. Thanks to both of =
you for your help.

Regards,

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




















=0A

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See 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