Hoping somebody will be able to help me to understand how the following would work as well as why it would need to be done if that's okay?
I've got two domains.
domain-one.co.uk - this is the main domain and holds an SSL cert
domain-one-uk.com - this is another domain our client owns, it's not secure and they want it to redirect to the first domain.
Is this simply going to be a case of adding a 301 rule in the htaccess file in the public folder or do I need to do anything with the DNS settings?
I added the following but it didn't seem to work
RewriteCond %{HTTP_HOST} ^www\.domain\-one\-uk\.com$
RewriteRule ^$ https://www.domain-one.co.uk/? [L,R=301]
Would appreciate any help and teaching anyone can provide.
Thank you
If there is no existing URLs to redirect and this is only a domain redirect, i'd go for a basic 301 redirect in the .htaccess on the insecure server, which will redirect anything that arrives there to the new domain :
Redirect 301 / https://secure-domain.net/
If the insecure server used to have content that is also available on the secure server (with the same URLs, besides the protocol and domain), then you indeed need to use RewriteRules, eg. :
RewriteEngine On
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
In your case, the missing "RewriteEngine On" certainly caused the redirect not to work.
The RewriteCond that checks the current domain name is only needed if this htaccess is used by both domains (ie. they are handled by the same server, using the same directory).
Related
I have the following issue and can't find a solution. Also I am not sure if this does work at all.
I have two domains. domain.de and domain.com
The german site has the domain domain.de. As soon as the domain domain.com is being used the redirect shall be to domain.com/en/. In other words. Only if the domain.com is used it shall be redirected to domain.com/en/.
But at the same time there are other URLs. e.g. domain.com/en/about-us/ .. or domain.com/it/bieno/. They all should not be affected.
Is it possible to redirect only the domain domain.com to domain.com/en/ and at the same time all other URLs would still be working?
It is a TYPO3 9.x installation btw. Perhaps I can solve this in TYPO3?
Eric
If you're using Apache (or a different webserver which supports this) you can use mod_rewrite to achieve this by adding the following to your .htaccess (replacing the domains of course):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
Rewriterule ^/?$ https://example.com/en/ [L,R=301]
The RewriteCond checks if the domain is example.com or www.example.com. If you only need it to work for example.com, you can remove (www\.)?. ^/?$ checks if the requested path is / or empty.
If you use the default .htaccess for TYPO3, you don't need RewriteEngine On, but you will need to add this somewhere after the existing RewriteEngine On and before RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L]. I'd add it right after RewriteEngine On.
I am getting this error in cpanel in the Add Redirect section after creating an add-on domain:
There was an error adding the redirect. Redirecting "https://example.com"
will cause a redirection loop because "http://.*/", which is located at
"/home/folder/", is above "https://example.com", which is located at
"/home/folder/"
Type = Permanent (301) redirection
All Public Domains
Redirects to: "https://addonDomain"
Wild Card Redirect
Preferably through cpanel, the goal is to redirect only through 301 redirect, for SEO purposes, and redirect the primary domain to the add-on domain. How to fix this loop? Thanks!
You can use via .htaccess
Edit with this code:
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301,NC]
Change yourdomain.com with your domain name. This work for me.
My domain http://vietnam.asiastreetfood.com works fine. But if somebody calls http://www.vietnam.asiastreetfood.com theres an error. I cannot enter www.vietnam as a subdomain at 1und1.de. So any ideas how i can redirect the www to the non-www domain?
This is what i tried:
RewriteCond %{HTTP_HOST} ^www\.vietnam.asiastreetfood\.com [NC]
RewriteRule (.*) http://vietnam.asiastreetfood.com/$1 [R=301,L]
I think that 'www' is technically a subdomain itself or at least a prefix not generally used with a "sub-domain", so in order to get www.sub.domain.com you have to configure a vhost on the server (much more complicated than an htaccess). Here is a Media Temple article I found as a starting point.
But this won't be possible on 1und1.de - you will have to contact their support and see if they can configure this (unlikely).
I ran a duplicate checker for my website and got the following message
WWW/NonWWW Header Check: FAILED Your site is not returning a 301
redirect from www to non-www or vice versa. This means that Google may
cache both versions of your site, causing sitewide duplicate content
penalties.
Is this something that i should be worried about and if so how should i fix it ?
You shouldn't be worried about it, allot of sites are configured that way and google knows that.
However you can still add this if you want to be safe and send your visitors and google always go to example.com instead of www.example.com
Add this to your .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I've redirected my domain http://domain1.com to http://domain2.com using a 301 redirect.
Now i would like to redirect subdomain.domain1.com to domain2.com/folder when the user arrives on that url.
Can I do this in dns? Or in some other way?
Thank you for your help!
You can not do this with DNS. DNS is used to map domain names to IP address(es). It can not resolve a domain to a specific URI.
If you use an Apache server you can achieve this using .htaccess file. You can try adding following lines to the file and see whether it works.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?subdomain.domain1\.com$
RewriteRule ^(.*)$ http://www.domain2.net/subfolder$1
(or)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.domain1\.com$
RewriteRule ^(.*)$ www.domain2.net/subfolder$1
Rewriting internal DNS can be a pain, and I had exactly this problem so I wrote a system to solve it. Yes it uses the third party server to effectively do the redirection for you, but all you need is 2 DNS entries and it will work. Test it out. https://redir301.link/
Use requires the addition of 2 DNS records. One as a pointer to this service, and an additional record as the destination point. DNS RFCs prevent a CNAME record also having an associated TXT record so one needs to improvise.
To use, you need to set up the subomain to point to redir301.link. (don't forget the DOT at the end!)
subdomain.foo.com 14400 IN CNAME redir301.link.
Then set the associated TXT record to the destination URL. TTL should be set to a MINIMUM of 300 (5 min).
301.subdomain.foo.com 14400 IN TXT "<destination URL>"
Destination URL can be any URL but the sub-subdomain needs to be 301 otherwise it will fail.
You can mix DNS and Nginx to easily solve this trouble.
On your DNS provider create an A record going to your server running Nginx.
On your server on /etc/nginx/sites-enabled create a file containing this lines:
server {
server_name subdomain.mydomain.com;
rewrite ^ http://www.adifferentdomain.com$request_uri? permanent;
}