Forum Moderators: phranque

Message Too Old, No Replies

Redirecting several directories to a new domain

Will this code in the .htaccess work?

         

anax

1:26 am on Apr 30, 2006 (gmt 0)

10+ Year Member



I need to do a permanent redirect of the contents of a directory to another directory on a new domain. In other words, I want all visitors to mysite.com/olddir/ and any page within it, to be redirected to newsite.com/newdir/ or the corresponding internal page. (All the individual files within olddir and newdir will be the same; it's just changing the first part of the URL.)

Is this the proper line to put into .htaccess on mysite.com:

redirect 301 /olddir/ [newsite.com...]

That seems much too easy, so it can't be right.

jdMorgan

12:32 pm on May 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks right to me. Did you test it before posting here?
If so, what appears to be the problem?

Jim

anax

2:16 am on May 3, 2006 (gmt 0)

10+ Year Member



It seems to work on simple static files, but I'm moving what is effectively a WordPress blog (I'm using WordPress like a CMS), and the redirect enters an indefinite loop and the browser cancels it. Wordpress creates an .htaccess file to manage its connections, and there must be some kind of interaction between my simple redirect and the Wordpress-generated .htaccess.

Shown below is my simple redirect line on oldsite.com, and then the Wordpress-generated .htaccess within newsite.com/newdir. I know most of it is repetitve; there must be something in the general matching pattern that is causing the loop in all cases.
-----------

## One line in the .htaccess in the root of oldsite.com: ##

Redirect Permanent /olddir/ [newsite.com...]

## Contents of .htaccess in newsite.com/newdir: ##
## Most of this is generated by WordPress ##

RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^newsite\.com
RewriteRule (.*) [newsite.com...] [R=301,L]

IndexIgnore *
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /newdir/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=45]
RewriteRule ^(tags)/trackback/?$ /newdir/index.php?pagename=$1&tb=1 [QSA,L]
RewriteRule ^(tags)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?pagename=$1&feed=$2 [QSA,L]
RewriteRule ^(tags)/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?pagename=$1&feed=$2 [QSA,L]
RewriteRule ^(tags)/page/?([0-9]{1,})/?$ /newdir/index.php?pagename=$1&paged=$2 [QSA,L]
RewriteRule ^(tags)(/[0-9]+)?/?$ /newdir/index.php?pagename=$1&page=$2 [QSA,L]
RewriteRule ^feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?&feed=$1 [QSA,L]
RewriteRule ^(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?&feed=$1 [QSA,L]
RewriteRule ^page/?([0-9]{1,})/?$ /newdir/index.php?&paged=$1 [QSA,L]
RewriteRule ^comments/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?&feed=$1&withcomments=1 [QSA,L]
RewriteRule ^comments/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?&feed=$1&withcomments=1 [QSA,L]
RewriteRule ^comments/page/?([0-9]{1,})/?$ /newdir/index.php?&paged=$1 [QSA,L]
RewriteRule ^search/(.+)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?s=$1&feed=$2 [QSA,L]
RewriteRule ^search/(.+)/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?s=$1&feed=$2 [QSA,L]
RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /newdir/index.php?s=$1&paged=$2 [QSA,L]
RewriteRule ^search/(.+)/?$ /newdir/index.php?s=$1 [QSA,L]
RewriteRule ^category/(.+)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?category_name=$1&feed=$2 [QSA,L]
RewriteRule ^category/(.+)/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?category_name=$1&feed=$2 [QSA,L]
RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ /newdir/index.php?category_name=$1&paged=$2 [QSA,L]
RewriteRule ^category/(.+)/?$ /newdir/index.php?category_name=$1 [QSA,L]
RewriteRule ^author/([^/]+)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?author_name=$1&feed=$2 [QSA,L]
RewriteRule ^author/([^/]+)/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?author_name=$1&feed=$2 [QSA,L]
RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /newdir/index.php?author_name=$1&paged=$2 [QSA,L]
RewriteRule ^author/([^/]+)/?$ /newdir/index.php?author_name=$1 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /newdir/index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /newdir/index.php?year=$1&monthnum=$2&day=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /newdir/index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /newdir/index.php?year=$1&monthnum=$2 [QSA,L]
RewriteRule ^([0-9]{4})/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&feed=$2 [QSA,L]
RewriteRule ^([0-9]{4})/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&feed=$2 [QSA,L]
RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /newdir/index.php?year=$1&paged=$2 [QSA,L]
RewriteRule ^([0-9]{4})/?$ /newdir/index.php?year=$1 [QSA,L]
RewriteRule ^([0-9]{4})-([^/]+)/trackback/?$ /newdir/index.php?year=$1&name=$2&tb=1 [QSA,L]
RewriteRule ^([0-9]{4})-([^/]+)/feed/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&name=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})-([^/]+)/(feed¦rdf¦rss¦rss2¦atom)/?$ /newdir/index.php?year=$1&name=$2&feed=$3 [QSA,L]
RewriteRule ^([0-9]{4})-([^/]+)/page/?([0-9]{1,})/?$ /newdir/index.php?year=$1&name=$2&paged=$3 [QSA,L]
RewriteRule ^([0-9]{4})-([^/]+)(/[0-9]+)?/?$ /newdir/index.php?year=$1&name=$2&page=$3 [QSA,L]
</IfModule>

# END WordPress

anax

10:48 pm on May 3, 2006 (gmt 0)

10+ Year Member



Now the whole new site is in some kind of redirect loop and can't even be accessed directly, let alone via a redirect from the old site.

BananaFish

10:38 am on May 7, 2006 (gmt 0)

10+ Year Member



First, obviously you'd have to get your new site working. I'd just stick with what wordpress generates, then add your own stuff piecemeal to see which directive is causing the problem.
Then on the old site you'd probably want your redirect to look like this so it will redirect any page:
RedirectMatch 301 ^/olddir/(.*) [newsite.com...]