I wish to redirect an entire domain except for 1 subdomain to another site.
I'm trying to get:
http://domain.com
http://www.domain.com
to redirect to another website/domain.
I want subdomain.domain.com to remain unaffected.
So far I have only managed to get either the www or the non www versions to redirect but not both at the same time.
Any assistance would be much apreciated.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com
RewriteRule ^(.*)$ http://www.another-domain/$1 [R=301,L]
Related
I'm trying to add some rules to an .htaccess file in a subdomain to:
Remove the www from the subdomain (if present) (E.g.: www.subdomain.domain.com to subdomain.domain.com)
Redirect to the /beta subdirectory (E.g: subdomain.domain.com to subdomain.domain.com/beta)
I have the second part only:
# Redirect to /beta
RewriteEngine On
RewriteRule ^$ /beta [L]
I've seen a couple of examples here in StackOverflow but they seem to work only for domains, not subdomains. Any help would be appreciated.
To redirect old domain to new domain this should do:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com$ [NC]
RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [R=301]
Note that I omitted the L directive here ([R=301,L]) because you are probably going to add the second directive (/beta redirect) right after this.
This is how I am attempting to force www and HTTPS urls in htaccess right now.
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
The problem is that this still creates a redirect loop. It first redirects to https://example.com and then redirects to https://www.example.com
Is there a way to correctly write this in htaccess so that it redirects to both https and www at the same time eliminating the redirect loop?
I have tried many examples that I have found here on stackoverflow and they all render redirect loops. Is this unavoidable?
Thanks!
I want to create a redirect via htaccess but not for my entire site, only for one page.
so while olddomain.com should work as normal I want to forward traffic on oldomain.com/xyz to newdomain.com
Try below rule if work change to R=301,
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/xyz
RewriteRule ^ http://newdomain.com [R=302,L]
I've been searching all over and have found problems similar to this but not the same.
I want domain.com to redirect to news.domain.com, however, I want domain.com/page to stay at domain.com/page.
Currently I'm using:
RedirectMatch 301 http://domain.com[/] http://news.domain.com
But it moves domain.com/page to news.domain.compage (which obviously isn't even a valid address).
If you just redirect the domain name alone, you can do that in your .htaccess:
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^$ http://news.domain.com [R=302,L]
Change to [R=301,L] when that work well.
I need to redirect WWW and non-WWW domain to different domain ending. Both domains are on the same cPanel.
How do I do that via .htaccess? This is my current .htaccess:
RewriteCond %{HTTP_HOST} ^abc\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.abc\.com$
RewriteRule ^/?$ "http\:\/\/www\.abc\.co\.nz\/" [R=301,L]
It depends what you want to redirect. But for example if you wanted to redirect a page called abc to a website: def.com you would use:
redirect 301 /abc http://def.com
Not sure if this is exactly what you want but I hope it helps.
In that case then all you need to do is put this code in your .htaccess of domain.com:
redirect 301 / http://domain.co.nz
This will redirect any part of domain.com to domain.co.nz