htaccess 301 redirecting of subdomain - home page issues - apache

I needed to 301 redirect my subdomain URL to the Directory structure URL.
So blogs.mydomain.com should be redirected to www.mydomain.com/blog/ and below is the .htaccess that is changed.
RewriteCond %{HTTP_HOST} ^blogs.sampledomain.com
RewriteRule ^(.*)$ http://www.sampledomain.com/blog/$1 [L,NC,QSA,R=301]
It works fine and the blogs part is taken care. But, when I try to go to www.sampledomain.com it takes me to www.sampledomain.com/blog.
With this I am not able to land onto the homepage at all.

Related

How do I redirect an entire site to a new domain using .htaccess?

I have a site that is moving to a new URL, an exact copy of the original with the same pages and URL structure. I'm working with the old domain's .htaccess file to redirect to the new one, and have this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com$
RewriteRule (.*)$ http://newsite.ca/$1 [R=301,L]
The redirect works when I go to oldsite.com or www.oldsite.com works as expected, and redirects to newsite.ca
However, when I go to something like oldsite.com/blog/, no redirect happens. It just stays at the same URL.
I want to be able to redirect every page to the new site, not just the root.
oldsite.com/blog/ should redirect to newsite.ca/blog/
I need this for the whole site without having to go through and redirect every single page individually. Is this possible?
Figured it out-
I moved my code to the top of the .htaccess file.
The code wasn't being executed because there was a www to non-www before it. Apparently the code is run in order, and if a redirect is found, it will not run another kind of redirect following it.

.htaccess redirect all pages except the home page

I have just merged two websites. Site A is now merged with site B.
Site A has got a .htaccess file which redirects all of the content to the new domain where site B is hosted.
RewriteRule (.*) http://www.siteb.com/$1 [R=301,L]
It is working perfectly, however, I need the homepage of site A not to redirect.
What do I need to add to the code above to make that happen?
Just change .* to .+ to make sure your regex pattern isn't matcinng landing page:
RewriteRule (.+) http://www.siteb.com/$1 [R=301,L,NE]

htaccess subpage on subdomain to subpage on other subdomain

I have trouble finding out the right approach to make a 301 redirect from one subdomains page to another subdomains page.
For instance:
subpage1.mysite.com/contact
needs to be redirected to
subpage2.mysite.com/kontakt
(i have a few hundred of these)
I have a lot of 301 redirects in my .htaccess so far, but they only redirect from the maindomain mysite.com/page.
I cant make a 301 like this, right?
It does not work..
301
Redirect 301 http://subpage1.mysite.com/contact http://subpage2.mysite.com/kontakt
I only can access the primary htaccess file on the main domain (mysite.com)
Read some about RewriteCond but it seems they take all of my subpages and redirect them to the other subdomain. That is not exactly suitable for me, as the url's have changed names and are not identical on the subdomains.
I've figured it out by using this.
Taking the subdomain as RewriteCond
#Consultancy redirects
RewriteCond %{HTTP_HOST} ^consultancy.madebydelta.com [nc]
RewriteRule ^about/$ http://testlab.madebydelta.com/om-os/ [R=301,NC,L]
RewriteRule ^industries/$ http://testlab.madebydelta.com/cases/ [R=301,NC,L]

How to redirect to another page using htaccess

I have 2 websites 1 old website and 1 new website. both are on different domains. now the old website had many urls like www.test.com/sadfd/dsf etc etc... all these urls are indexed by google. So when users click these urls I want them to redirect to www.newdomain.com
I had added a redirect using redirect in htaccess but then if the base url is www.domain.com/something/something it will redirect to www.newdomain.com/something/something.. but that url does not exist. I need all visits to redirect to www.newdomain.com
how can I do this?
I'm not the master of the .htaccess file but you can use this snippet, it redirects all pagerequests to the domain without adding the path:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?name-of-domain\.net$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.net/ [R=301,L]

301 redirect addon domain improperly

I have a website with url http://abc.com/myfolder/, now i add a addon domain "xyz.com" in cpanel and point it to myfolder. The addon domain is working successfully. xyz.com is showing what http://abc.com/myfolder/ showing. However http://abc.com/myfolder/ is already indexed in google, thus i want to do a 301 redirect from http://abc.com/myfolder/ to xyz.com. I searched online and did something like below.
RewriteEngine On
RewriteBase /myfolder/
RewriteRule ^(.*)$ http://www.xyz.com/$1 [R=301,L]
but the redirect failed. showing "The page isn't redirecting properly". What can i do
you have first to check that the host is abc.com before applying the rule, otherwise, you end up applying the rule for both abc.com and xyz.com which result an infinite redirection loop.
RewriteEngine On
RewriteCond %{HTTP_HOST} abc.com$
RewriteRule ^myfolder/?(.*)$ http://www.xyz.com/$1 [R=301,L,NC]