301 Direct to new Domain on https:// not https://www - .htaccess

I am looking to 301 an entire domain on https://www.olddomain.co.uk to a new domain on https://newdomain.com via .htaccess. Currently, the version I have will only work if you manually remove the www from the old link showing in Google SERP for the old domain listing - so it shows 'This site can’t be reached' when clicked. Removing the 'www' part of the URL and hitting return performs the redirect.
Current .htacess is:-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
</IfModule>
And I've also tried:-
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.co.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.co.uk [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]
Important to keep the SEO value form the old domain. Any assistance appreciated here.
Thanks in advance
Glennboy

Fixed in 2 parts:-
The DNS settings on the domain did not cover 'www' which was a simple error that would have stopped 'www' showing anyway.
Added a valid SSL Certificate to the old domain to ensure safe traversing of SSL - SSL
In short, the issue was not the .htaccess implementation which was perfectly valid and now working fine.

Related

How to add www before subdomain in htaccess

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.

.htaccess redirect folder to subdomain

I've tried applying a few of the answers found on stackoverflow, but either I'm missing something or I'm plain dumb.
Basically I got a main domain name. This domain already has a non-www redirect. So http://domain.com becomes http://www.domain.com. This domain also has a mobile version found inside the the 'm' folder. So accessing the domain name like http://www.domain.com/m/ works and so does http://m.domain.com. What I'm trying to achieve is simple: anyone whom goes to the site via http://www.domain.com/m/, or http://www.domain.com/m/about should be redirected to the subdomain version so to http://m.domain.com or http://m.domain.com/about in the second case listed above.
Whatever I tried implementing ended up with errors, either I managed to disable direct access to m.domain.com, but it worked via domain.com/m/, or redirect loops.
Thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file of domain.com main .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^m/(.*)$ http://m.%1/$1 [L,NC,R=302]
# non-www to www
RewriteCond %{HTTP_HOST} !^(m|www)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,NC,R=302]

.htaccess Redirect from sub.domain.com.au* to www.domain.com.au/URL

I am attempting to redirect a development site that has been indexed by search engines to a specific category in the new live site.
The development site URL was:
http://staging.mydomain.com.au/
There are multiple page url's after the domain so I'd like to redirect all of these to the same new URL.
E.g.
http://staging.mydomain.com.au/essential_grid/
http://staging.mydomain.com.au/feed/
The new url is, where "/portfolio/" is where I need the old URLs redirected to:
http:www.mydomain.com.au/portfolio/
While I'm not receiving any error messages, staging.mydomain.com.au is
not redirecting to www.mydomain.com.au/portfolio/
This is a snippet of what I have in my .htaccess file at present:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^staging.mydomain.com.au$
RewriteRule ^(.*)$ http://www.mydomain.com.au/portfolio [R=301,L]
</IfModule>
Any help would be greatly appreciated.
UPDATE: It seems (from comments) that staging. no longer exists - that's the problem! staging. needs to exist (ie. the DNS must resolve) so that the request gets to your server in order to do the redirect. If staging. does not exist then the initial request will simply fail (the browser will fail to lookup the domain and you'll get a DNS error).
You need to recreate the staging subdomain (even with no files) and then implement the redirect below.
Your RewriteRule actually looks OK - assuming you are wanting to redirect all those URLs to the single /portfolio URL. However, the order should perhaps be changed to have the redirect before the internal rewrite. RewriteEngine only needs to be included once and you don't need RewriteBase in the code you have posted. So, this should be rewritten as:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^staging\.mydomain\.com\.au$
RewriteRule ^ http://www.mydomain.com.au/portfolio [R=301,L]
^(.*)$ is reduced to simply ^ since you don't need to capture the URL for a backreference in the substitution.
I've also removed the other RewriteRule as it doesn't appear to be doing anything?
Also note that 301 redirects are cached by the browser, so make sure that you clear your browser cache between failed attempts. It can be easier to test with 302 temporary redirects for this reason.

How to Re-Direct non WWW, non HTTPS to WWW, HTTPS without Multiple Re-Directs?

I hope you can help with this htaccess issue please? I basically have the htaccess rules working apart from in one scenario. This is the case where a user visits the site on a non HTTPS and non WWW links.
Re-Directs
User visits on http/non-WWW URL
User is redirected initially to the http/WWW URL
User is then redirected to https://www.website
You can see the behaviour here:
http://childrens-curtains.co.uk
All other scenarios work fine.
I want to try to remove the 2nd redirect from the sequence so it behaves like this:
User visits on http and is immediately redirected to the https/www version without the 2nd step (if that makes sense?)
The current scenario causes multiple re-directs, which I understand is a bad approach from an SEO perspective.
This is my htaccess redirect rule:
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [L,R=301]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context
You can try this code keepin into .htaccess file.
To add www add following code.
RewriteCond %{HTTP_HOST} ^**domainname**\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domainname\.com$
RewriteRule ^index\.html$ "http\:\/\/www\.domainname\.com\/" [R=301,L]
To add http add following code.
RewriteCond %{HTTP_HOST} ^domainname.com [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
Which will add both http as well as www to URL.
Thanks.

Redirect www.example.com to example.com

I've a domain hosted on bluehost with iLister CMS installed in, the problem which I'm facing is http://www.advett.com/admin isn't responding because I registered advett.com/admin in the site_url field of iLister license.
How to redirect all the request for www.advett.com and www.advett.com/admin to advett.com and advett.com/admin respectively?
I know it can be done with .htaccess but I've not been able to find a solution till now.
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.advett\.com [NC]
RewriteRule ^(.*)$ http://advett.com/$1 [L,R=301]

Resources