i have migrated a domain from olddomain.com to newdomain.com...i want all URLs to redirect from olddomain.com to newdomain.com. I got this part working. My issue now is that I have a CNAME on newdomain for help.newdomain.com -> externaldomain.com (uses referrerURL to land on proper page)
I need to redirect help.olddomain.com -> help.newdomain.com -CNAME-> externaldomain.com
Is this possible with .htaccess rewrite? if not, is there another way to skin it?
Yes, a 301 .htaccess rewrite should do it. Put this in the server that currently serves help.olddomain.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^help.olddomain.com [NC]
RewriteRule ^(.*)$ http://externaldomain.com/$1 [L,R=301,NC]
If you really want it to hit help.newdomain.com first, use that in the RewriteRule instead.
Related
So, we printed some cards but the card accidentally has www.sub.domain.com/example but when to try to go there it says the site cannot be reached but If we try to go to sub.domain.com/example it works.
The main website is made in WordPress but the landing pages (subdomains) are made using Unbounce can this be fixed using .htaccess? if so then which .htaccess file and how can we fix this.
Thank you
You need to redirect your www to non-www. That can be done by adding this to your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Don't forget to change yourdomain with your domain.
I have a main ssl domain https://www.a.com and a normal addon domain http://www.b.com on the same server. I use this .htaccess rule for a.com to redirect an old page in that website to a new one:
Redirect permanent /my_page.php /my_page
It works just fine. When i access a.com/my_page.php it redirects to a.com/my_page. The problem is that the addon domain b.com has the same page name inside its folder, so when i access b.com/my_page.php it also redirects to b.com/my_page. I need to prevent this redirection for the addon domain.
Note: I have tried to use this redirection rule instead but it didn't work at all:
RewriteRule https://www.a.com/my_page.php https://www.a.com/my_page
And this one too didn't work:
RedirectMatch 301 ^a.com/my_page.php$ https://www.a.com/my_page
After some reading and studying i was able to fix this using the RewriteRule instead. Here's the new code:
RewriteCond %{HTTP_HOST} ^.*a.com$ [NC]
RewriteCond %{REQUEST_URI} ^/my_page\.php$ [NC]
RewriteRule ^(.*)$ https://www.a.com/my_page [L,R=301]
I have my website in a subdomain:
subdomain.mydomain.co.uk
Now, I don't want to move subdomain.mydomain.co.uk but I want to use .htaccess to set it so that when someone types: mydomain.co.uk the url still remains mydomain.co.uk but acually shows subdomain.mydomain.co.uk
How can I do this?
Try putting this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.co.uk [NC,OR]
RewriteRule ^(.*)$ http://subdomain.mydomain.co.uk/$1 [L,R=302,NC]
You could try doing an R=301, but beware of the dangers of using a 301 redirect. We had huge problems with our website at one point using 301 redirects as written about in this article: http://getluky.net/2010/12/14/301-redirects-cannot-be-undon/
I don't even know how to ask this question correctly, because I have never seen it done before. I am pretty competent with editing name servers, creating a records, and cnames etc, but I have no idea if this is even possible.
I have a client that owns a several domains that all point at the same site. So say the main domain is www.client-site.com. So then www.other-domain-1.com and www.other-domain-2.com are simply set as 301 redirects to point at www.client-site.com.
So all is good until now he is requesting that www.other-domain-1.com/facebook and www.other-domain-1.com/linkedin point to his facebook page or linkedin profiles instead of redirecting to the main domain.
The 301 redirect is happening at the registrar, and I don't believe there is a way to do what he wants from there. But I am thinking I could instead point it at the web host nameservers and include it as a addon domain, and then use the .htaccess file to do the 301 redirect of only the hostname, and then redirect as desired the hostname/paths.
So what is the proper way to do this? Something like...
Redirect 301 http://other-domain-1.com/facebook http://facebook.com/account
Redirect 301 http://other-domain-1.com/linkedin http://linkedin.com/profile
Redirect 301 http://other-domain-1.com http://client-site.com
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]
# linked-in redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^linkedin/?$ http://linkedin.com/profile [L,NC,R=302]
# rest of the redirects
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^ http://client-site.com%{REQUEST_URI} [L,NE,R=302]
So the Solution that worked on my server based on anubhava answer above was
facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]
Then after getting them all working changed the R=302 to R=301 to make the redirects permanent.
A client wants to redirect a domain (oldsite.com) to a new domain & subdirectory (newsite.com/subdirectory). I have this code setup and it works for for oldsite.com, but when I test oldsite.com/subdomain I get a 404 at newsite.com.
Redirect 301 / http://www.newsite.com/subdomain/
Is there a way to handle any subdomain requests at oldsite.com so they all redirect to newsite.com/subdirectory? Maybe a wildcard?
You can use this in the .htaccess of the web root of the old site:
RewriteEngine On
RewriteRule ^subdomain/(.*) http://newsite.com/subdirectory/$1 [B,NE,R,L]
Try this:
RewriteCond %{HTTP_HOST} oldsite\.com [NC]
RewriteRule (.*) http://newsite.com/subdirectory/$1 [QSA,L]