301 Redirect where 2 domains point to same IP? - .htaccess

I have 2 TLDs example.com and example.ie.
example.com and example.ie both point at the same IP address and pull the same content now we could get whacked with a ban hammer from Google for duplicate content so we want anyone accessing *.example.ie and *.example.com to be redirected to www.example.com the problem is as they are both pointing at the same server the .htaccess is the same thus I don't believe we can do the usual:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So how do we go about creating a search-engine friendly 301 redirect from *.example.ie and *.example.com to www.example.com?

I would do it like this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]
That will redirect (statuscode 301 "permantly moved") every domain which is not www.example.com to www.example.com.

The 301 redirect you posted is just fine; the HTTP header of every request (nowadays) contains the name of the host.
As an alternative, you can use rel=canonical. It's not that urgent anyway, as duplicate content on just two domains is unlikely to be a problem.

Related

Redirect every page on example.com to example.org

I'm wanting every page of www.example.com to redirect to www.example.org
I'm using the following .htaccess in the root of example.com
RewriteEngine on
RewriteRule ^(.*)$ https://www.example.org/$1 [R=301,L]
if I navigate to www.example.com, I'm redirected to www.example.org - that's great
If I navigate to www.example.com/example.php I get a 404 from example.com
Edit: Cloudflare was caching files, the accepted answer as well as the method in the question work to redirect files to the appropriate page. If using Cloudflare, turn OFF caching by turning on development mode when in development
Check this 1:1 rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule (.*) http://www.example.org/$1 [R=301,L]

Only Allow requests from specific IP address to access subdomain & redirect all others to a different url - htaccess

I have a subdomain for our old store of store.mydomain.com . We just launched a new store at the root domain www.mydomain.com
How can we redirect all traffic from store.mydomain.com to www.mydomain.com for all traffic EXCEPT for those from a specific IP?
In other words we are trying to maintain internal access to store.mydomain.com because we have some things we still need to do with the old store (customer records, orders, etc...) but we don't the general public to be able to access any URI on the old store.mydomain.com subdomain. We want all of those people to be redirected to www.mydomain.com
The following works to redirect ALL traffic, but unsure of how to do the IP condition check.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^store.example.com$
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
Try:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78%
# etc...
RewriteCond %{HTTP_HOST} ^store.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]
So this will redirect for everyone except when the request comes from the IP:
1.2.3.4
12.34.56.78

How to redirect non-www to www with SSL for a specific domain not all parked domains

I have test.yoursite.com parked on example.com and have a SSL multi-domain certificate.
What I am asking is:
when http://example.com requested, .htaccess should redirect it to https://www.example.com;
when http://test.yoursite.com requested htaccess should redirect it to https://test.yoursite.com.
One of directions should work both with www and SSL redirection, another one is just for SSL redirection.
By the way I also have example.net parked on same host. I have tried several things which did not work. Waiting for your help.
Try
# Dealing with a domain with/without www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://www.%2.%3/$1 [L,R]
# Dealing with a domain that doesn't care about www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^([^\.]+)\.([^\.]+)\.([^\.]+)$
RewriteRule ^(.*)$ https://%1.%2.%3/$1 [L,R]
The first rule will redirect http://www.example.com/something to https://www.example.com/something as well as http://example.net/foo to https://www.example.net/foo
The second rule will redirect hosts that don't care about the "www", such as http://subdomain.domain.com/bar to https://subdomain.domain.com/bar
It will not, however, redirect http://sub-sub.subdomain.domain.com/.

Problem with .htaccess file and exclude command

I have a simple .htaccess which redirect non www to www domain
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
What I need to do is to exclude the IP calling from this redirect.
In other words I need that if someone call site by IP then it won't be redirected to www domain, it will call the IP itself and visitor can navigate all the site links without the 301 redirect. This means he will still navigate the site through the IP.
Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
It looks to see if the host does not start with www and if so it redirects to the www URL. It won't match the IP address or any other subdomains (i.e. test.example.com)

Redirect One domain to another on the same IP

I've got two sites, lets call them example.com and example2.com.
The website used to only be accessible via example.com but our client wanted to change their name so they registered example2.com. Now example.com and example2.com are now pointing to the same website.
I need an htaccess rule that will direct all traffic accessing the site via the old domain example.com and 301 redirect it to the new domain example2.com.
I know it's going involve at least one REWRITE_COND but I don't know what syntax I need.
Nevermind, I figured it out. Here's my solution:
# Redirect Traffic from old domain
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example2.com/$1 [R=301,L]

Resources