Forum Moderators: phranque

Message Too Old, No Replies

Rewrite/Redirect folder to subfolder

         

jonas21

6:03 pm on Nov 24, 2009 (gmt 0)

10+ Year Member



Hello,

i am trying to do the following:

I need to redirect all requests going to
www.domain.net/customer/...
to
www.domain.net/shop/customer/...

all arguments/urls/query strings etc must be included. So far i have been unable to get this working...any help greatly appreciated.

Regards,
Jonas

jdMorgan

6:44 pm on Nov 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best-effort code as a basis for discussion, and describe any trouble you're having.

Thanks,
Jim

jonas21

7:37 pm on Nov 24, 2009 (gmt 0)

10+ Year Member



RewriteEngine On
RewriteCond %{REQUEST_URI} ^www.domain.net/customer/

Options +FollowSymlinks
RewriteRule ^/customer$ /shop/customer/ [R]
RewriteRule ^/customer(.+) [domain.net...] [R,L]
RewriteRule ^customer/$ /shop/customer/$1

thats what i tried so far...

jdMorgan

8:31 pm on Nov 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This one is closest, but still several problems...

Options +FollowSymlinks
RewriteEngine On
#
RewriteRule ^/customer(.+) http://www.example.com/shop/customer/$1 [R,L]

1) The URL-path examined by RewriteRule in .htaccess will not start with a slash -- in fact, the entire URL-path used to reach "this" .htaccess file's directory will be removed.

2) The pattern "customer(.+)" requires at least one character to follow "customer".

3) The [R] flag, specified without an argument, defaults to a 302-Found redirect; Search engines will keep the old URL in their database, and not update it to reflect the new URL.

With a few additional tweks for 'neatness', try this:


Options +FollowSymlinks
RewriteEngine on
#
RewriteRule ^customer(/.*)?$ http://www.example.com/shop/customer$1 [R=301,L]

If what you really need is an external redirect, then that should do it.

Jim

g1smd

1:19 am on Nov 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have a RewriteCond, it will apply ONLY to the single RewriteRule that follows it (so the Options line is in the wrong place).

Leading / on pattern is needed only if the code goes in httpd.conf. Omit the / if the code is in .htaccess.

The R flag should specify R=301 otherwise you get a 302 redirect.

Your third rule uses the $1 backreference which is undefined. There is no () construct in the pattern.

The third rule will never be processed as the second rule will already have matched and sent the user to

http://www.domain.net/shop/customer[b]//[/b]
.

There are a lot of issues to address in the sample code.