Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

redirect from one folder to another not working

     

starchild

2:04 pm on Jul 1, 2011 (gmt 0)

10+ Year Member



Hi,

I know this sounds like such a simple question, but nothing I've tried actually works.

All I want to do is redirect say

www.domain.com/folder1/name/id/1 to www.domain.com/folder2/name/id/1

The rule should redirect all pages within folder1, to folder2


Closest I get is:

RewriteCond %{REQUEST_URI} ^/folder1/*
RewriteRule ^(.*)$ [domain.com...] [R=301,L,NC]

...but it ends up like /folder1/folder2/#*$!#*$! instead.

What am I doing wrong please?

lucy24

8:47 pm on Jul 1, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



You're not capturing the string "folder1" by itself. You have to capture it in order to get rid of it. Or, in this case, to replace it. Don't do anything else with the rest of the address; you don't need anchors unless you've carelessly used the "folder1" name in some other unrelated location too.

Use "example.com". The forums convert everything else-- even if it's just as phony-- into an active link. We need to see what you actually typed.

starchild

11:47 am on Jul 2, 2011 (gmt 0)

10+ Year Member



Hi Lucy,

I was using this:

RewriteCond %{REQUEST_URI} ^/folder1/*
RewriteRule ^(.*)$ http://www.example.com/folder2/$1 [R=301,L,NC]

g1smd

11:57 am on Jul 2, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The
(.*)
pattern captures ALL of the requested URL. The
(.*)
pattern is greedy, promiscuous and ambiguous.

Adjust the pattern to capture only the bits you want to re-use in the new URL request.

RewriteRule ^unwanted(wanted)$ http://www.example.com/folder2/$1 [R=301,L]

starchild

11:48 am on Jul 3, 2011 (gmt 0)

10+ Year Member



Thanks everyone.