homepage Welcome to WebmasterWorld Guest from 54.166.122.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirect for moving domains
pro_seo

5+ Year Member



 
Msg#: 4223228 posted 7:50 am on Oct 28, 2010 (gmt 0)

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

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



 
Msg#: 4223228 posted 4:32 pm on Oct 28, 2010 (gmt 0)

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

5+ Year Member



 
Msg#: 4223228 posted 9:09 pm on Oct 28, 2010 (gmt 0)

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

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



 
Msg#: 4223228 posted 12:17 am on Oct 29, 2010 (gmt 0)

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

Jim

pro_seo

5+ Year Member



 
Msg#: 4223228 posted 7:05 am on Oct 29, 2010 (gmt 0)

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

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4223228 posted 10:33 am on Oct 29, 2010 (gmt 0)

Never mix Redirect and RewriteRule directives in the same site.

Change that redirect to use the RewriteRule syntax.

pro_seo

5+ Year Member



 
Msg#: 4223228 posted 11:59 am on Oct 29, 2010 (gmt 0)

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

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



 
Msg#: 4223228 posted 1:46 pm on Oct 29, 2010 (gmt 0)

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+ Year Member



 
Msg#: 4223228 posted 5:39 pm on Oct 29, 2010 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved