1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regarding .htaccess Redirection

Discussion in 'White Hat SEO' started by charlesbritto, Jun 13, 2013.

Tags:
  1. charlesbritto

    charlesbritto Newbie

    Joined:
    Apr 3, 2013
    Messages:
    9
    Likes Received:
    0
    Occupation:
    SEM Executive
    Location:
    India
    Hi,

    I'm newbie of web development. I want to redirect & access all domain1 sub folder files to domain2 with the help of .htaccess. For example, domain1/folder to domain2. My all files have only in domain1. If i enter domain2 in address bar, domain2 want to access domain1 all files, but domain1 won't show in address bar. Ex. if enter domain2/sample, it wants access domain1/sample. Can anyone give me the full .htaccess file redirection code.

    Thanks in advance.
     
    Last edited: Jun 13, 2013
  2. weblues

    weblues Jr. VIP Jr. VIP Premium Member

    Joined:
    Oct 4, 2008
    Messages:
    2,508
    Likes Received:
    437
    Home Page:
    Change folder1 and domain2 to match your domain1 folder and your domain2 URL and put the modified code in your domain1 .htaccess file.

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^folder1(.*)$ http://www.domain2.com/ [L,R=301]
    
    </IfModule>
    
     
    Last edited: Jun 13, 2013
  3. charlesbritto

    charlesbritto Newbie

    Joined:
    Apr 3, 2013
    Messages:
    9
    Likes Received:
    0
    Occupation:
    SEM Executive
    Location:
    India
    Thanks for your reply, i want redirect all files not only one folder or one file. If i want means, i want to write code for all files or folder ah, for you given above or that code is enough for redirect all pages.
     
    Last edited: Jun 13, 2013
  4. Endire

    Endire Elite Member Premium Member

    Joined:
    Mar 27, 2012
    Messages:
    1,756
    Likes Received:
    1,061
    Gender:
    Male
    Charlesbritto,

    If I understand you right, you want to redirect everything that's on domain1 to domain2?

    If so, there are different ways to configure this (assuming you already have pages indexed or linked-to that were on domain1).

    If you don't care where people are landing from the redirect, you won't have to insert as many directives in your .htaccess file. Note that content does not need to remain on domain1 unless you are still having people visit pages there. All that needs to be in that directory is the .htaccess file with your redirects.
    Your Syntax would look like this

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain1.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.domain1.com$
    RewriteRule ^$ http://www.domain2.com/$1 [R=301,L]
    </IfModule>
    The code above is configured as a permenant redirect and will redirect any visits to either domain1.com or www.domain1.com to www.domain2.com.

    Also note that the .htaccess file applies only to the directory that it is in and all directories underneath the one that it is in. Also note that the directives in the file are applied in the order in which they are written. If you go to redirect individual pages that have similar paths, you must put URLs with shorter paths last, otherwise the URL's with longer paths will not be redirected properly and will cause an internal server error.

    Here is more info on .htaccess for you,

    https://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file?

    Hope that helps,

    Shawn
     
  5. charlesbritto

    charlesbritto Newbie

    Joined:
    Apr 3, 2013
    Messages:
    9
    Likes Received:
    0
    Occupation:
    SEM Executive
    Location:
    India
    That code is working for home page only. But, rest of domain1 pages(inner pages) are not working in domain2. Can you assist me?
     
  6. Endire

    Endire Elite Member Premium Member

    Joined:
    Mar 27, 2012
    Messages:
    1,756
    Likes Received:
    1,061
    Gender:
    Male
  7. charlesbritto

    charlesbritto Newbie

    Joined:
    Apr 3, 2013
    Messages:
    9
    Likes Received:
    0
    Occupation:
    SEM Executive
    Location:
    India
    Thanks for your reply. Let you explain clearly, domain1 will listed multiple domains like domain2, domain3, domain4,.... If i click domain2 it'll open separate window for domain2 but that all domain2 files are in domain1. Just have to access all files in domain 1. But, in address bar we want to show only domain 2. And i cannot post link here. If i try to post links in my post, it won't publish. I'll PM to the sample links.

    Thank you.
     
  8. charlesbritto

    charlesbritto Newbie

    Joined:
    Apr 3, 2013
    Messages:
    9
    Likes Received:
    0
    Occupation:
    SEM Executive
    Location:
    India
    Hi,

    spis-online . dk this is the sample link, i want redirect like that.
     
  9. Endire

    Endire Elite Member Premium Member

    Joined:
    Mar 27, 2012
    Messages:
    1,756
    Likes Received:
    1,061
    Gender:
    Male
    Charles,

    You will have to move all of the files over to the domain2 directory from domain1. If those files remain in a directory under domain1, you will not be able to view them in domain2. You could have the files in both locations however if you aren't using domain1 for any other purpose other than a redirect, there doesn't need to be any files present in that directory other than your .htaccess file.

    Best,

    Shawn
     
  10. subster

    subster Elite Member

    Joined:
    Apr 5, 2008
    Messages:
    1,864
    Likes Received:
    1,448
    Location:
    Krauthausen
    Charles, simply point domain2 to the physical folder of domain1 and them do the .htaccess mod
     
  11. CyberDragon

    CyberDragon BANNED BANNED

    Joined:
    Jun 21, 2013
    Messages:
    53
    Likes Received:
    11
    That code is working for home page only?