Regarding .htaccess Redirection

charlesbritto

Newbie
Joined
Apr 3, 2013
Messages
9
Reaction score
0
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:
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:
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:
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
 
That code is working for home page only. But, rest of domain1 pages(inner pages) are not working in domain2. Can you assist me?
 
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.
 
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
 
Charles, simply point domain2 to the physical folder of domain1 and them do the .htaccess mod
 
Back
Top