Redirect domain name to a specific page - .htaccess

I have theses domain names installed :
Main domaine name : www.example.com
Others domains : www.example.org, www.example.fr, www.animals.com
I first make a rule on my .htacess to redirect all traffic from theses domain names into my main domain www.example.com with the "https" :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
I have then a rule to rewrite my URL like that :
RewriteRule ^([a-z]{2})-([0-9]+)-(.*)\.html$ index.php?lang=$1&menu=$2 [L]
The structure of my urls are the following :
https://www.example.com/fr-10-my-page-about-animals.html
I need to promote this page on internet, but the URL is pretty difficult to remember and my main domain name : www.example.com is to generic. So I bought the domain name : www.animals.com
So I want that my visitors arrive on this page https://www.example.com/fr-10-my-page-about-animals.html with this (easy to remember) URL : www.animals.com
I do have 2 very specific and important pages on my website that I want to promote though an easy to remember and short URL.
What is the best practice regarding Search Engines (Google) ? Is it a good idea, good practice to do it ?
Should I make a 301 redirection, so I can give to people this www.animals.com URL to visit my page, they will be then redirected and their browser will display https://www.example.com/fr-10-my-page-about-animals.html
Or is there a possibility to print www.animals.com as the URL on the browser when https://www.example.com/fr-10-my-page-about-animals.html is called ?
I would really need your advice and help regarding this topic and more informations on how to achieve it in the most Google Friendly way.
Thank you very much.

Related

How to redirect entire domain to new domain except homepage via htaccess

So I have found some questions that are close to what I need, but I haven't found exactly what I'm looking for.
While I've worked with htaccess files in the past, it's pretty much been just copying and pasting code that is proven to work, or just doing simple 301 redirects. To be honest, I get pretty confused when looking at htaccess rewrite rules, so unfortunately are not going to be able to do from scratch. So I'm really hoping there is someone kind enough to provide a code example just using placeholder domain names.
Here is my situation. I'm doing work for a company who has split up into different divisions (4). So they want to take the site on their current domain, move it to a different domain. Then put up a simple html splash page on the old domain that provides links to the 4 different sites they will have (one of those being what was the old site on a new domain).
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage. Not sure if this matters, but site that was on the old domain was a WordPress site so technically is index.php. But the new site/splash page is named index.html.
Thanks in advance!
So I need to redirect everything from olddomain.com to newdomain.com with the exception of the homepage.
You can use this rule in the site root .htaccess of olddomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(css|js|images)/ [NC]
RewriteRule . http://newdomain.com%{REQUEST_URI} [L,NE,R=301]
RewriteRule . will match everything except the home page just make sure this rule is the first rule in your .htaccess.

Another .htaccess redirect case

I have a site where mydomain.com and mydomain.com/frontpage serves the exact same content.
Socalled SEO experts tell me it is very bad to have the same content on different addresses. Google will cast upon me a terrible fate.
So I thought fine, I'll just redirect mydomain.com to mydomain.com/frontpage, but I'm failing miserably. I just can't wrap my head around htaccess commands.
I need to have visitors who visits mydomain.com or www.mydomain.com to be redirected to www.mydomain.com/frontpage in a way to that it becomes visible in the browser address field.
BUT nothing else must be redirected.
For example, www.mydomain.com/anotherpage must still be there.
My .htaccess is already full of a lot of rewrite rules that redirects all of these user-friendly addresses to the real urls (index.php?pageid=341) etc. So I'm thinking I would first redirect mydomain.com to mydomain.com/frontpage and then let another RewriteRule later make sure that mydomain.com/frontpage actually points to index.php?pageid=341.
But mydomain.com => mydomain.com/frontpage must be a visible redirect, while all the other rewrite rules are hidden from the user.
How does the Redirect or RedirectMatch or RewriteRule look like, that redirects visitors from www.mydomain.com to www.mydomain.com/frontpage while keeping other addresses like e.g. www.mydomain.com/anotherpage ?
Thanks.
You can insert this new rule just below RewriteEngine On line:
RewriteRule ^/?$ /frontpage [L,R=301]

Prevent Subdomains being viewed/crawled

cPanel only allows me to create 'AddOn' domains. I have pointed all my TLDS to the server which saves them under 'public_html/main/sites' directories '/site1.com' , '/site2.com' etc. mainwebsite.com will be served under 'public_html' and all my client sites under 'public_html/main/sites'
It also creates subdomains 'username.mainsite.com' How can i prevent google from indexing those subdomains yet still index the TLDS. And stop users from being able to access the TLD from the subdomain too?
If i created a RewriteRule would google still index the TLD? Or is there a better way to go about this?
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.site1\.com$ [NC]
RewriteRule ^(.*)$ http://www.site1.com/$1 [L,R=301]
If the 301-redirect works (for you), it will work for search engines, too.
See Google’s documentation:
301 redirects are particularly useful in the following circumstances:
[…]
People access your site through several different URLs. If, for example, your home page can be reached in multiple ways - for instance, http://example.com/home, http://home.example.com, or http://www.example.com - it's a good idea to pick one of those URLs as your preferred (canonical) destination, and use 301 redirects to send traffic from the other URLs to your preferred URL.

Best way to change domain names

I have a blog which i get about 1200 visits a month lets say the blog domain name is.
exampleblog.com
What i want to do is complete change the domain name to say.
iamsam.com
What is the correct way to do this should i map the domain iamsam.com to my exampleblog.com account on my hosting then put a 301 redirect in the htaccess to redirect traffic to the correct domain ie.
Options +FollowSymlinks
rewritecond %{http_host} ^exampleblog.com [nc]
rewriterule ^(.*)$ http://www.iamsam.com/$1 [r=301,nc]
Is this the correct way to do this???
Can someone advise me thanks
Yes, that is exactly the way to do it, assuming the URL scheme for the new domain is exactly the same as the old domain.
You might also want to capture users that use the old address and display some sort of notification on the new website, so that they'll notice the change and update their bookmarks.

Unable to show siteA's content at siteB by domain masking

I have a domain www.siteA.com, which uses Joomla, while the domain www.siteB.com is empty.
I would like to show the content of the domain www.siteA.com at www.siteB.com.
I tried to solve the problem first by making a domain redirection by .htaccess, but I could not show SiteA's content at SiteB.
How can you show the contents of mysiteA.com at mysiteB.com by domain masking in .htaccess?
You really should be doing this by CNAME-ing the domain, but if you really want to use .htaccess you can do what #Unkwntech suggests
Edit: It would just look like
www.siteB.com CNAME www.siteA.com
Whichever way you do it (CNAME or htaccess) you're probably going to get an SEO penalty for duplicate content.
RewriteEngine On
RewriteRule ^.*$ http://www.siteA.tld/$1 [NC]
This should rewrite every request to siteA.

Resources