Forum Moderators: phranque

Message Too Old, No Replies

Redirect Subfolder

         

martinacastro

11:14 pm on Nov 4, 2010 (gmt 0)

10+ Year Member



Hello

can someone tell how can I use Redirect 301 in htaccess to redirect:

www.mysite.com/articles/ to www.mysite.com/articles/archive/

and

www.mysite.com/articles/index.php to www.mysite.com/articles/archive/

Thanks and regards
Martin

g1smd

11:27 pm on Nov 4, 2010 (gmt 0)

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



The index redirect code has been posted more than a thousand times previously.

What have you tried so far for the other redirect? It is likely that a RewriteRule with [R=301,L] flags will be a better solution than using "Redirect" syntax.

martinacastro

12:13 am on Nov 5, 2010 (gmt 0)

10+ Year Member



@g1smd

Thanks for your post

I put in the .htaccess file of the subfolder article:

RewriteRule ^(.*)$ archive/$1 [R=301,L]

g1smd

12:36 am on Nov 5, 2010 (gmt 0)

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



The target URL should include the protocol and domain name.

As coded, you have an infinite loop, as the new URL will re-match the pattern.

To fix that, add a preceding negative match RewriteCond looking for "archive", and to not redirect if that string is present within the request.

martinacastro

12:44 am on Nov 5, 2010 (gmt 0)

10+ Year Member



@g1smd

Thanks for your post, I not know much about .htaccess but I must put something like this?

RewriteCond ^archive\[NC]
RewriteRule ^(.*)$ www.mysite.com/articles/archive/$1 [L,R=301]

Thanks

martinacastro

4:32 am on Nov 6, 2010 (gmt 0)

10+ Year Member



Can some help to know what is wrong here:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /subfolderA(/[^\ ]*)?\ HTTP/
RewriteRule ^subfolderA(/(.*))?$ [mydomain.com...] [R=301,L]

Thank you
Martin

jdMorgan

7:02 pm on Nov 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{THE_REQUEST} ^[A-Z]+\ /subfolderA(/[^\ ]*)?\ HTTP/
RewriteRule ^subfolderA(/(.*))?$ http://www.mydomain.com/subfolderA/subfolderB/$2 [R=301,L]

This says, if the client-requested URL starts with "subfolderA", then redirect to /subfolderA/subfolderB.

As such, requests for /subfolderA/subfolderB/ will also get redirected to /subfolderA/subfolderB/subfolderB, and then to /subfolderA/subfolderB/subfolderB/subfolderB. This will continue, and you will have an "infinite" redirection loop.

You must explicitly stop that loop using a *negative-match* RewriteCond:

RewriteCond $2 !^/subfolderB/
RewriteRule ^subfolderA(/(.*))?$ http://www.mydomain.com/subfolderA/subfolderB/$2 [R=301,L]

Jim

martinacastro

12:39 am on Nov 30, 2010 (gmt 0)

10+ Year Member



Thanks Jim