Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect for moving domains

     

pro_seo

7:50 am on Oct 28, 2010 (gmt 0)

5+ Year Member



ok friends, I've a situation here.

I am trying to make the following moves

www.olddomain.com to www.example.com/folder/

and subsequently..

www.olddomain.com/widgets/ to www.example.com/folder/widgets/

and it will go down even one more level, so

www.olddomain.com/widgets/green/ to www.example.com/folder/widgets/green/

I am trying to use the following code for the redirect

RewriteBase /
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?(.*)$ http://www.example.com/folder/$1 [R=301,L]

It's redirecting www.olddomain.com to www.example.com/folder/ but the other arrangements aren't working.

Kindly advise what I am missing here.

Thanks a lot!

jdMorgan

4:32 pm on Oct 28, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Your RewriteCond accomplishes nothing and can be removed.

The main reason I can think of that this rule might not work for olddomain subdirectories and sub-subdirectories is that perhaps RewriteOptions is set to "none" in your server config. Try adding
 RewriteOptions Inherit 

at the top (above RewriteBase) and see if that changes anything.

Content negotiation can also interfere. Try adding
 Options -MultiViews 


Another thing to try (on Apache 2.0 and above) is to disable AcceptPathInfo using
 AcceptPathInfo off 


And it goes without saying that if you have any other RewriteRules, Redirects, RedirectMatches, or Aliases in this file or in your server config files that may also redirect or rewrite the subdirectory and sub-subdirectory URLs, then they should be modified or deleted so that they do not preempt this rule so that it can work.

Also be sure to delete your browser cache before testing any new server code. Otherwise, your browser will show you stale pages and server responses.

Jim

pro_seo

9:09 pm on Oct 28, 2010 (gmt 0)

5+ Year Member



Thanks Jim for your reply

I tried out what you said but it still doesn't help :(

Now my .htaccess looks like this

Options +FollowSymlinks
RewriteEngine On

AcceptPathInfo off
Options -MultiViews
RewriteOptions Inherit
RewriteBase /
RewriteRule ^/?(.*)$ http://www.example.com/folder/$1 [R=301,L]

Let me know if I have them in the right order

I don't have any other rewrite rules except the one that Wordpress does while changing their permalink structure

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Thanks again!

jdMorgan

12:17 am on Oct 29, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



And where is the WordPress code in relation to your redirect rule?

Jim

pro_seo

7:05 am on Oct 29, 2010 (gmt 0)

5+ Year Member



It is exactly in the same order as shown above.

To update about the issue, I contacted the hosting support and they seemed to fix the redirection with this simple rule

Redirect / http://www.example.com/folder/

Was that so simple? :P

Thanks a lot for your help again Jim, you've always been very helpful :)

g1smd

10:33 am on Oct 29, 2010 (gmt 0)

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



Never mix Redirect and RewriteRule directives in the same site.

Change that redirect to use the RewriteRule syntax.

pro_seo

11:59 am on Oct 29, 2010 (gmt 0)

5+ Year Member



Never mix Redirect and RewriteRule directives in the same site.


Could you please explain why it's not a good idea to mix rewriterule and redirect?

Change that redirect to use the RewriteRule syntax.


I tried to accomplish that with the RewriteRule syntax but just couldn't get it to work.

I am very much open to getting the best solution to address this issue.

Thanks!

jdMorgan

1:46 pm on Oct 29, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If your redirect and your WP rewrite are in the same .htaccess file and in the order your show, then *all* requests will get redirected, and possibly multiple times. So it's likely I misunderstood your intent here.

The key question is, "Which domain do you want your WordPress to run in?"

Assuming you want to have WordPress at "www.example.com/" and that all requests for www.olddomain.com/ should be redirected to www.example.com/folder/ (bypassing WordPress), you'd need something like:

AcceptPathInfo off
Options +FollowSymlinks -MultiViews
#
RewriteEngine On
RewriteBase /
#
# Externally redirect all variations of olddomain.com/ to www.example.com/folder/
RewriteCond %{HTTP_HOST} ^([^.]\.)*olddomain\.com(\.|\.?:[0-9]+)?$ [NC]
RewriteRule ^(.*)$ http://www.example.com/folder/$1 [R=301,L]
#
# BEGIN efficiency-tweaked WordPress
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$ [NC]
RewriteCond $1 !^index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php [L]
# END tweaked WordPress

For more information on the improvements to the WP code, see Reducing Costly Rewrites in Wordpress [webmasterworld.com].

For more information on proper rule order and mixing mod_alias and mod_rewrite directives, see The Correct Order For Efficient htaccess [webmasterworld.com]

Both of these threads are in our Apache Forum Library.

Jim

pro_seo

5:39 pm on Oct 29, 2010 (gmt 0)

5+ Year Member



Thanks Jim for your detailed response.

The key question is, "Which domain do you want your WordPress to run in?"


Both of the domains are running on wordpress
 

Featured Threads

Hot Threads This Week

Hot Threads This Month