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
Related
I'm on a subdomain and only want to redirect from this subdomain shop.example.com to example.com, but I want all other urls from shop.example.com still to work and be kept. Like shop.example.com/checkout should not be affected by this rule only /
In the subdomain directory shop.example.com I tried this in .htaccess
Redirect 301 / https://example.com
But then all is redirected
Try with below rule, I am using mod_rewrite.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^shop\. [NC]
RewriteRule ^$ http://example.com [R=301,L]
I have a domain for which I would like to set up both a www and non-www redirect to https://newdomain.com.
So olddomain.com and www.olddomain.com should go to https://shinynewdomain.com.
#redirect http non-www to https://www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$
RewriteRule (.*) https://www.newdomain.com/$1 [R=301,L]
#redirect https non-www to www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^olddomain\.com$
RewriteRule (.*) https://newdomain.com/$1 [R=301,L]
This is the code I'm using, and it sends me to a domain parking page at my registrar instead of the new domain at a different host.
Am I doing anything wrong?
There are several ways you can do the redirection of your old website to your new website. If your website is made using wordpress then it will be more easy to achieve 301 redirections.
Method 1:
In Wordpress, what you can do is install the plugin Simple 301 Redirect.
Setup the plugin as you like.
Then you will find options in Settings after activating it.
Method 2
Another is using some code line in the .htaccess file.
In the web directory settings, you will find the access of .htaccess file.
Open the file in the editor and use the code below.
To redirect a single page: Redirect 301 /old-file.html http://www.example.com/new-file.html
To redirect to a new website: Redirect 301 / http://www.new-example.com/
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]
This code affect my subdomains as well.
Redirect 301 /some-adress /
For example "subdomain1.domain.com/some-adress" will redirect to "subdomain.domain.com/"
I only wanted to redirect "domain.com/some-adress" to "domain.com/". Not the subdomains. How can I prevent it from redirecting the subdomain?
You can convert that rule into mod_rewrite with a condition to allow this rule for main domain only.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^some-adress / [L,R=301]
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]