.htaccess redirecting with two domains - .htaccess

I currently have two registered domains that redirect to the same hosting package. So, as an example I have the following two domains:
www.domain1.com (Attached to the hosting)
www.domain2.com (just redirects to www.domain1.com)
Both go to the same index page.
However, I would like to change this so that surfing to www.domain1.com would make you stay on the default index file and that surfing to www.domain2.com (or without the www) would make you go to a seperate folder (example www.domain1.com/domain2)
I'm guessing manipulating the .htaccess file is the way to go?

RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain2.com
RewriteRule ^index.html index2.html
Not sure what your default index file is, but you can edit the Rule to match.

Related

Exclude Redirect rule on an Alias domain - for specific file (Robots.txt)

I have my main site: example.com that contains all files on its root folder.
I have a new domain example.net, that I want users to use as an alias domain, so users will actually see the exact content of example.com and its files, yet see in their address bar the site example.net.
But, I don't want Google to index example.net site at all, as this would be duplicate content.
Therefore, I want to exclude it using robots.txt, but if I use an alias domain, it will try to read robots.txt of example.com.
What can be the solution? any way to exclude the file?
You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} example\.net$ [NC]
RewriteRule ^robots\.txt$ robots-net.txt [NC,L]
Add your robot rules in the file robots-net.txt to be read with robots.txt but only when accessed from example.net.

.htaccess, DNS & linkstructure

what I'm trying to achieve is forwarding a domain to a subdirectory of my web server.
I need to have several 3rd party domains pointing to the same content whit preserving the link structure.
So no matter if I type in example.com/page1 or example.nl/page1 or example.eu/example1 there should be always the same content.
Any ideas how to achieve that?
If the goal is to server different content under the different domains, assuming you have a directory structure where each domain is a directory under DocumentRoot, you could use:
RewriteEngine On
RewriteCond %{HTTP_HOST} (\.com|\.eu|\.nl)$ [NC]
RewriteRule .* %{HTTP_HOST}/$1 [L,PT,NS]
Otherwise, just pointing DocumentRoot for all domains at the same DocumentRoot will suffice, albeit with SEO risks.

301 redirect for domain change

My friend would like to change her domain oldsite.com to newsite.com.
The hosting company is lukrativedomains and they suggested changing the domain to newsite.com and then forwarding oldsite.com to newsite.com
However, the forwarding feature they offer will redirect all pages to the root newsite.com. I want to be able to forward all the individual pages of oldsite.com to the same page on newsite.com
Do I need to copy the content from oldsite.com to newsite.com and then implement a 301 redirect? If so, how do I do that and would that be duplicate content?
Also, how would I go about doing the 301 redirects for each page? What do I need from her? (htaccess? if so where would that be?)
As of right now, newsite.com does not have anything on it, it is just a parked page but I want it to look exactly like oldsite.com.
It is very important to do this while minimizing effects on SEO. She does not use wordpress, in fact, I am not really sure where the content lives (I am guessing on ftp somewhere)
here are my steps that i would do in this case
Create a full site backup (files and databases)
Upload them to the new site and check that everything works fine.
In the root folder (usually if you are using Cpanel that would be the public_html folder) i would create and .htaccess file with the 301 redirections
Code example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^oldpage.html$ http://www.newsite.com/newpage.html [R=301,L]
</IfModule>
Take a good look at the 3ed line whats going on,
I say RewriteRule and then "^" and the name of the page, that looks like in full url like this: http://www.oldsite.com/oldpage.html
So for example lets say that you want to redirect this url:
http://www.oldsite.com/categories/business/news.html
You would put it like this:
RewriteRule ^categories/business/news.html$ http://www.newsite.com/categories/business/news.html [R=301,L]
If it does not end with .html .php it would look like this:
RewriteRule ^categories/business/news/$ http://www.newsite.com/categories/business/news/ [R=301,L]
Also if you would like to learn a bit more about redirections i would suggest reading this article: http://moz.com/learn/seo/redirection

Using wildcard subdomain on specific directory

I am setting up an existing wordpress install to use multisite. I have successfully set up the network and since it was an existing install it uses subdomains (which I wanted anyways).
I have created a new site/subdomain on my network so it would look something like this example.domain.com
The issue I am running into is getting wildcard subdomains setup on my hosting provider BlueHost.
I am hosting multiple domains so when I setup a wildcard it always points to the root or original ip address.
I need it to point to a specific directory of the root so it uses the correct wordpress install. root/specific-directory
Is there a way to achieve this? I am not too familiar with a and cname issues. If there is a way to achieve it by writing in the htaccess that would be okay too.
I am hosting multiple domains so when I setup a wildcard it always points to the root
I'm assuming you meant that you get the same content for example.domain.com as if you were visiting www.domain.com. This can surely be handled through htaccess rewrite rules.
If a sub-domain named subsite was to be served out of ${DOCUMENT_ROOT}/subsite directory, you would add the following rules to your .htaccess placed at your web root / directory:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^subsite\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subsite [NC]
RewriteRule ^(.*)$ /subsite/$1 [L]
If there are several mutisite subdomains that need redirection, use the following dynamic rules instead:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
RewriteRule ^(.*)$ /%1/$1 [L]
You would also need to add ServerAlias *.domain.com to your <VirtualHost> configuration in Apache's httpd.conf file.
It seems BlueHost doesn't take up any requests to modify httpd.conf directly for you. But, they do provide a way to setup a wildcard subdomain from their Control Panel.
Take a look at How to Set Up a WordPress MultiSite in Bluehost. The last section outlines the process with screen shots. You also need to enable theme per site for your subdomains.
1- You can add your subdomain as an addon domain and it can have a separate subdirectory as you want.
2- Another way to achieve this is using another host for subdomians. On the second host you set up your subdomains and point your subdomains from your main host to subdomains on the secondary host.

htaccess rewrite all pages to same page on another domain

So I've been looking but so far can;t find something that I'm looking for exactly. Looked at this article How can I forward ALL pages to the same exact page on a different domain using .htaccess? but it seems to only redirect my home page.
Currently, I'm using WordPress and I need to be able to forward all pages to a new domain. For example, domain1.com/about-us needs to go to domain2.com/about-us. But I have about 50 pages this needs to work on. I would like to see if there is a 1-5 line code to use for this to work.
Thanks!
Try putting this (above any wordpress rules) in the htaccess file in domain1.com's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain1.com [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301]
If your 2 domains are one different webservers, or don't share a common document root, you can just use mod_alias, adding this to the htaccess file in domain1.com's document root:
Redirect 301 / http://domain2.com/

Resources