I need to redirect my website to a new domain name but I want it to also redirect all of the pages. I want www.myoldsite.com/ to redirect to www.mynewsite.com/ but I also want all of the pages to redirect.
For example: www.myoldsite.com/faq to redirect to www.mynewsite.com/faq and so forth and so on. I know how to do it by doing each individual page but I have a lot of pages. How do I rewrite the 301 for it to basically change the root domain name but keep the directories and pages the same? Thanks a million!
You just need this in the htaccess file in your old domain's document root:
Redirect 301 / http://www.mynewsite.com/
If both your old site and new site share the same document root, then you need mod_rewrite instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myoldsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mynewsite.com/$1 [L,R=301]
Related
I am trying to use htaccess to redirect ALL pages from a domain to a specific page on a new domain. Yes, I completely understand we will loose SEO value this way.
I currently have a cpanel redirect that makes this url:
https://www.kiss1047.net/
go to this
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
but that doesn't get any of the internal pages to redirect. I would also like all internal pages (here is an example):
https://www.kiss1047.net/listen-live
to also go to:
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
I have tried a few things, but they always carry over the page url, ie above /listen-live/
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/listen-live/
and that results in a 404.
is there some htaccess magic i can employ here?
In your .htaccess file .. Make a single entry that looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://mytown-media.com/stations/kiss-104-7-kxnc-fm/ [R=301,L]
This will direct ALL TRAFFIC (.*) to your other website .. Regardless of file name or directory .. And will not append the file/directory to the end of the URL .. IE listen-live
This is a 301 Permanent redirect [R=301,L] .. Which means once followed by Google, will be indexed as such .. Also will cache in users browsers so that the browser remembers the 301 instead of bouncing between websites as well.
This command in .htaccess redirects every page of your old domain to new domain's one specific URL.
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L]
For your case:
RewriteEngine on
RewriteRule ^(.*)$ https://mytown-media.com/stations/kiss-104-7-kxnc-fm/ [R=301,L]
In result:
https://www.kiss1047.net/listen-live
will be redirected to:
https://mytown-media.com/stations/kiss-104-7-kxnc-fm/
I am palling to migrate my website from the .co.nz to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly without any 404 pages from .co.nz version
All https://
I want "https://www.example.co.nz/" to go to "https://www.example.com"
Which will also redirect
https://www.example.co.nz/contact to go to https://www.example.com/contact
https://www.example.co.nz/men to go to https://www.example.com/men
Many Thanks
This should do the trick:
Redirect 301 / https://www.new-example.com/
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-example.com$ [NC]
RewriteRule ^(.*)$ https://new-example.com/$1 [L,R=301]
You put this in the .htaccess file of the .co.nz domain. This will redirect all your content and subfolders to their appropriate subfolders on the new domain (so example.me/subfolder to example.com/subfolder) AND also force redirect to https part.
Recently I built a site with php but the old site they had was all in HTML. So now I dont know what what is the best way to redirect all those old links to the new site (maybe redirect all links with HTML to the main domain) with .htaccess, what is the best practice ?
Here is what I have tried but the site says to many redirect loops:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.de
RewriteRule (.*) http://www.example.de/$1 [R=301,L]
RedirectMatch "\.html$" http://www.example.de
So first we redirect all non-www links to www, then when the page has .html in the end to redirect to the main site.
Option 1: Redirect all old .htmllink to new sites's /
RewriteEngine On
RewriteRule \.html$ / [L,R=301,NC]
Option 2: If .html file name and .php file names are same then redirect all old .htmllink to new sites's .php /
RewriteEngine On
RewriteRule ^(.+?)\.html$ /$1.php [L,R=301,NC]
Depends, if it is a new domain you need to point to, add a domain pointer from the old domain to point towards the new domain, this will resolve in the server handling the redirect, this is the most efficient way.
This will work better than .htaccess because it's faster and does not cause a second initial page load (due to redirect).
If you don't have access to the server or domainpointers you could make the index.html an index.php file if php runs on the old server, from here simply put:
header('Location: http://www.newdomain.com/');
This will automatically redirect.
Hope this helped you.
‐ Sid
I have a htaccess which will redirect all subdomain to parent domain except one domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.theonlytutorials\.com$ [NC]
RewriteCond %1 !^(blog|www)$ [NC]
RewriteRule ^(.*)$ http://theonlytutorials.com/$1 [L,R=301]
This code was working fine in my previous hosting. But in Godaddy it doesn't seems to be working.
It is redirecting, but to the exact hosting location.
One of my URL structure:
www.theonlytutorials.com/video/58/4496/ChessBaseGmbH
Instead it is redirecting to:
www.theonlytutorials.com/others/tutorials/video/58/4496/ChessBaseGmbH
Where others / tutorials are the folders created in my hosting
On Go Daddy (and probably some other Hosts) the site folder names should be included in your redirect code.
RedirectMatch 301 ^/site-folder-name/video/58/4496/ChessBaseGmbH/$ http://the full URL here where you want the redirect point to
If you wanted to redirect a link from the /blog/ folder / site to another site
RedirectMatch 301 ^/blog/video/58/4496/ChessBaseGmbH/$ http://the full URL here where you want the redirect point to
Let's say you want to do a redirect from a site that is in this folder /others/ and you want to redirect to your root domain.
RedirectMatch 301 ^/others/video/58/4496/ChessBaseGmbH/$ http://the full URL here to your root domain where you want the redirect to point to
And logically the same thing would probably be true if you have this folder structure /others/another-nested-folder/
RedirectMatch 301 ^/others/another-nested-folder/video/58/4496/ChessBaseGmbH/$ http://the full URL here to your root domain where you want the redirect to point to
I'm trying to redirect a few pages to a new domain and I have done this before but for some reason I can't get the code to work.
RewriteEngine On
Redirect 301 http://domain.com/page1.html http://domain2.com/page1.html
Can anyone see where I'm going wrong?
In .htaccess file the below code will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Since you say you only want to direct a FEW of your pages and not all of them, you can do:
RewriteEngine On
Redirect /~myaccount/oldpage.html http://www.newsite.com/newpage.html
You specify the path to the page on your current server followed by the URL to redirect to.
OR you can do:
RedirectMatch 301 ^/oldpage\.html$ http://www.newsite.com/newpage.html