I relative newbie to 301 redirects and I'm currently trying to set up redirects for an old site to a new site with dynamic urls and I'm not 100% sure I'm doing it right.
The new site is different from the old and on a new domain, both have a mix of static and dynamic urls which is making the redirects seem rather complicated.
I have the code below to redirect http://oldsite.co.uk/shop/products.php?cat=80 to http://newsite.co.uk/product
RewriteCond %{HTTP_HOST} ^oldsite\.co\.uk$ [NC]
RewriteCond %{QUERY_STRING} ^cat=80$ [NC]
RewriteRule ^shop/products\.php$ http://newsite/product? [R=301,NE,NC,L]
Can anyone tell me if this is correct?
Also, I'm a little unsure on the correct format for redirecting static to dynamic eg.
redirecting http://oldsite.co.uk/shop/contact.php to http://newsite.co.uk/index.php?route=information/contact
One other thing I was unsure about is how to catch urls without creating individual redirects. I have nearly 2000 products on the site but rather than redirect them all I'd like to redirect the main category urls and have the products ust redirect to the main home page or category if that's possible.
Thanks
Related
I am changing my website from a dynamic CMS-system (Umbraco) to a static classic .HTML. It is the on the same domain, but the URL will change.
Example: The URL is changing from:
www.example.com/information
To:
www.example.com/info.html
My question is:
What is the best way to redirect while keeping the best SEO page rank.
I am thinking about 301 redirect through .htaccess, but I am not sure if I should redirect my new to .html urls to the old dynamic …/example - or the other way?
Or maybe there is a different better way?
I do have a fine 404.
Also I need the right redirect code for .htaccess - if that's the right way.
I hope you guys can help me out.
I haven't try anything out yet, because I don't wanna do 301 before the site go live.
You need to implement 301 redirects from the old URL to the new URL in order to preserve SEO and ensure that any "old" links that have been bookmarked or linked to from other websites still work.
Exactly how you implement the 301 redirect (either in your server-side script or in .htaccess) does not really matter. However, if you are moving to an entirely static site then .htaccess is likely the only option you have.
I am not sure if I should redirect my new to .html urls to the old dynamic …/example - or the other way?
You need to redirect from the "old" URLs to the "new" URLs that you are using/linking to on the new site. (It makes no sense to redirect the other way as that would just break everything!)
You can probably just use the simple mod_alias Redirect directive.
For example, to 301 redirect from /information to /info.html you could do the following:
Redirect 301 /information /info.html
Bear in mind that 301 redirects are cached persistently by the browser. To prevent caching issues it is advisable to test first with a 302 (temporary) redirect.
Have you considered keeping the same URLs? This would obviously negate the need for implementing redirects. You could employ URL-rewriting if the underlying file is called info.html. For example, using mod_rewrite:
RewriteEngine On
RewriteRule ^information$ info.html [L]
The above would internally rewrite a request for /information to info.html. The user only sees /information in the browser address bar, but info.html is served from your site.
Taking this further, it would be easier if the new "file" is simply the same as the old URL, just with a .html extension. For example, the URL is /information and the underlying file is information.html. You can then use a single rule to rewrite all your URLs. For example:
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^/.]+)$ $1.html [L]
The above assumes the old URLs do not contain additional slashes (ie. consist of a single path segment. In other words, all files are in the document root) and do not contain dots.
White
I finally got my page ready to go live, and i changed all my new URLS to the same name as the old URL, just with a .html extension - as u said. After that i used:
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^/.]+)$ $1.html [L]
And it works fine.
I do have a question about if a "RewriteRule ^(.*).html$ /$1 [L,R=301]" would be better? I mean both "/page.html" and "/page/" works, and this could mess with my former SEO ranking?
Also: what do u think of this:
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
And by the way. Do you use "page.html" or just "/page" in your href to prevent the .html showing?
//MM
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 have a question similar to this
URL rewrite for part of domain name
Tried to use that rule but it didn't work. I think the url rule could be different.
I have the url:
olddomain.com/test/ref/s/page
olddomain.com/test/ref/s/page1
olddomain.com/test/ref/s/page2
I need to rewrite them and maintain the last part of the url, eg:
https://www.newdomain.com/test/ref/s/page
https://www.newdomain.com/test/ref/s/page1
https://www.newdomain.com/test/ref/s/page2
Edit:
The ending of the url is dynamic so using individual redirection for each link is not practical.
Much thanks for any help.
You can use your .htaccess file to do this, similar to the answer you are referencing. If you just want to send your old urls to your new urls individually, you can achieve this quite easily using the Redirect 301 function inside .htaccess, and uploading to the root of "old domain", like so:
Redirect 301 /test/ref/s/page https://www.newdomain.com/test/ref/s/page
Redirect 301 /test/ref/s/page1 https://www.newdomain.com/test/ref/s/page1
Redirect 301 /test/ref/s/page2 https://www.newdomain.com/test/ref/s/page2
This will individually 301 the index at each of the old urls to the corresponding new url.
If you want to redirect everything from "old domain" to "new domain" just use a rewrite like so:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]
You would, of course, need to configure this depending on your use of SSL.
I am looking for a 301 redirect. I have a OC 1.5.1.3 (abc.com) and have a new store now on OC 2.0.3.1 (xyz.com ). I have migrated my data from abc.com to xyz.com and since all the product / pages urls are the same except the domain change, i am looking for a simple code which i can add to htaccess to make this happen.
Since my old website urls are listed on Google, i would like to redirect the traffic coming to a particular url to the same page on the new website. It would be a permanent redirect.
I paid a freelancer to get this done.. was in a hurry. Anyways, i have posted the answer below for the benefit of all.
Upload this to .htaccess on your old domain abc.com, replace example.com with your new domain name.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !example.com/$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
I have two domains example.uk.net and example.co.uk - the example.uk.net has been in use since the website was started but i want to change over to the .co.uk version now - both domains are currently pointing to the same IP/sever - you see the same website on both domains...
Now i know i need to 301 redirect from the .uk.net to the .co.uk but i've read that it is best to do this page by page to retain google rankings/listings and also it is best practise anyway now i just can't seem to get this working as both domains point to the same site i can't use rewrite rules in the htaccess file such as...
Redirect 301 /get-a-quote/ http://example.co.uk/get-a-quote/
i also seem this piece of code on here that did seem to work but only for the main page, not any sub pages also it still doesn't work on a per page basis only redirecting the whole site...
RewriteCond %{HTTP_HOST} !^example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://example.co.uk$1 [R=301,L]
If anyone could help me out that would be brilliant or if someone has handled something similar in the past - any pointers would be awesome...
Thanks
You were missing a /:
RewriteCond %{HTTP_HOST} !^example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://example.co.uk/$1 [R=301,L]