htaccess 301 redirect for webshop transfer - apache

I searched stackoverflow but couldn't find a solution that fits my need. On top of it, if must admit, that regex is a pretty difficult thing for me. So here is the thing:
I have a new webshop (domain-new.com) that has basically the same products of old shop (weird product urls, weird categories, everything weird, ...) but on a new technology, new domain and proper URLs. Thus, I would like to close the old shop and transfer the SEO rankings with a 301 redirect to the new domain/shop.
My solution is that the old shop/domain serves a .htaccess file with a lot of links:
RewriteEngine On
Redirect 301 / http://www.domain-new.com/ ###front page
Redirect 301 old-weird-product-path1 http://www.domain-new.com/new-product1.html
Redirect 301 old-weird-product-path2 http://www.domain-new.com/new-product2.html
Redirect 301 old-weird-product-path3 http://www.domain-new.com/new-product3.html
Redirect 301 old-weird-product-path4 http://www.domain-new.com/new-product4.html
I could manage to link about 300 products and categories but can't manage to do the hole list of 5000 products and categories.
Is there a way to add a line of code that says: "and for everything else, thats not listed above, redirect to the front page of the new webshop?
Thanks in advance and sorry, if the question was answered somewhere else. I couldn't find the proper solution.

This may be possible with regex match if you have a common pattern in weird urls.
Then Regex not match common url pattern and redirect to home page of new website something like
RewriteEngine on
RewriteRule [^old-weird-product-path] http://www.domain-new.com/ [R=301,L]
You may have to refine it as per url structure.

Related

Oscommerce to OpenCart Redirects

The way that Oscommerce SEO Friendly URLs work, is that they are generated from a product or category title followed by a p for product and c for category, then the product or category ID. For categories, each parent directory ID is also used.
for example:
https://example.com/jeep-pinion-gears-c-284_845.html
over the course of many years, products and categories get edited and moved therefore changing the URL. However, all the old URL's still resolved because pages are served strictly based off of the last part of the URL. It looks for the c or p and the ID's. SEO is still able to be maintained.
For Example:
https://example.com/jeep-pinion-gears-c-284_845.html
https://example.com/jeep-pinion-gears-and-accessories-c-284_845.html
https://example.com/jeep-pinion-gears-c-284_1234_845.html
https://example.com/ring-pinion-gears-c-845.html
Would all load the same content.
I've recently changed over to OpenCart where I used the latest URL for each product and category from the OsCommerce store. However, all the of Old Oscommerce URL's don't work.
I was originally writing some regex redirects to match the ID's but I'm running into redirect loop issues.
Does anyone any any ideas on a different approach?
If there is a way to derive the new OpenCart URL from your OsCommerce SEO URLs
RewriteCond %{REQUEST_URI} !^/.*?-[cp]-\d+\.html$
RewriteCond %{REQUEST_URI} ^/(.*?)-([cp])-[\d_]*?(\d+)\.html$ [NC]
RewriteRule (.*) https://new.example.com/%2-%3.php [R=301,L]
The important part here is the stop not rule to prevent looping redirects.
put it below others rewrites, removing a trailing slash or the www-subdomain, or http to https rewriting.
If three is no "simple relationship" between the two URLs you are out of luck and have to write a redirect for each of them. You should be able to generate the rules using the SEO URLs stored in the DB.
Redirect 301 /old-page.html http://www.example.com/new-page.html
Maybe a PHP redirect could be helpful too?
header("Location: http://www.example.com/new-page.html", true, 301);
exit();

301 rdirect for custom URL

I have a custom made image gallery site that I converted to WordPress, this site have few thousands link like this
http://www.example.net/Gallery?cmd=viewCarGallery&carID=13&pgID=1
http://www.example.net/Gallery?cmd=viewCarGallery&carID=9&pgID=1
All link is now converted to wordpress and now I am facing problem redirect them, I tried to using like this
Redirect 301 /Gallery?cmd=viewCarGallery&carID=9&pgID=1 http://www.example.net/gallery/gallery_ID
Please help me how can I redirect this kind of URL.
A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page.I added below codes in my .htaccess file.
Redirect 301 /oldfile.htm /newfile.htm
I think what you need is mod rewrite. Take a look here http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
It looks like a similar question https://superuser.com/questions/155139/htaccess-301-redirect-with-regular-expressions

guidelines for htaccess code to transition users to new website

Suppose I have an old website with 10 webpages, and I want to deprecate it and move visitors to a new website with 100 webpages.
Two of the webpages of the old website map directly to two corresponding webpages on the new website. All other pages on the old website should go to the new website's home page. How to set that up?
I know I can use .htaccess in the public_html folder of the old website to create some permanent redirect rules for individual pages. So for the two pages that need to map one-to-one, I can do:
Redirect 301 /oldfile1.htm http://www.example.net/newfile1.htm
Redirect 301 /def/oldfile2.htm http://www.example.net/123/456/newfile2.htm
But what about all the other webpages on the old website? This is where my knowledge of .htaccess lacks. Does the .htaccess stop executing when it reaches one of the redirects above? If so, then perhaps I simply place the following AFTER the above code to catch the remaining pages?
Redirect 301 / http://www.example.net/
Or, something else? Also, will the redirect directly above map all webpages it sees to the home page of the new website (I assume so), or a matching directory/webpage page on the new website? -- That is, I don't want the situation where http://www.olddomain.com/abc/Oldfile1234.html takes users to http://www.example.net/abc/Oldfile1234.html on the new website (rather, it should take users to http://www.example.net) since most webpages do not map one-to-one.
Lastly, in the .htaccess file on the old website public_html directory, how to account for users coming from https versus http, and www versus non-www URLs?
I'm hoping there's common strategy people use for this sort of thing, since it should be fairly common, so I don't have to re-invent one.
You should be using RedirectMatch for precise matching using regular expressions. You can place these rules in root .htaccess:
RedirectMatch 301 ^/oldfile1\.htm$ http://www.example.net/newfile1.htm
RedirectMatch 301 ^/def/oldfile2\.htm$ http://www.example.net/123/456/newfile2.htm
RedirectMatch 301 ^ http://www.example.net/

Proper 301 redirect for sites

I have a bit of a complex question. I am moving sites from
http://www.hikingsanfrancisco.com
to
http://www.comehike.com
The directory structures will not be the same throughout both sites. What are some of the best practice things I can do in order to retain most of my existing SEO strength in both the general domain and individual pages for searches related to the other pages?
Thank you,
Alex
If most of the URLs are staying the same and just the domain is changing, you could create an .htaccess file in the root folder at the old site with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.comehike.com/$1 [R=301,L]
This will make hikingsanfrancisco.com/some-page go to comehike.com/some-page.
Otherwise in that same htaccess file you could add a line for each redirect. So if hikingsanfrancisco.com/big-hikes is now going to comehike.com/even-bigger-hikes the redirect would look like:
Redirect 301 /big-hikes http://www.comehike.com/even-bigger-hikes
That 301 tells Google to now consider the new URL correct.
To redirect the whole site no matter what to the new URL you could use this:
Redirect 301 / http://www.comehike.com/
A 301 Redirect, page by page, is the best option (If you can use regular expressions is easier). Redirect the old page to a page in the new site with similar content.
Use the change of address tool in Google Webmasters tools.
Try to contact some of yours referrals to change the links that target your site.

Problems with mod_rewrite and 301 redirects from one dynamic url to another

Hey all, I'm having all kinds of problems with a bunch of apache redirects just now and could really use some help!
I'm wating to put in a 301 redirect for a load of urls from a client's old site to their new site in the following format;
Old - page.php?pageNum_rs_all=0&totalRows_rs_all=112
New - page/sub?foo=bar
The values in the query sting for the old site don't in any way tie up to any ids or references on the new site, I only want to match that specific request and redirect to the new page.
It feels like I've tried just about every combination of rewriterule I can find online but still nothing seems to be working. This is running on Apache 2.2.
The rule I started with (and keep going back to) is;
RewriteRule ^/page.php\?pageNum_rs_all=0&totalRows_rs_all=112 /page/sub?foo=bar [R=301,L,NE]
Any help would be greatly appreciated!
c.
The reason that this doesn't work is that RewriteRule can't see the QueryString. To get at the Query String, you need to use RewriteCond. See http://wiki.apache.org/httpd/RewriteQueryString for examples of how this works.
I've always tended to use use a series of 301 redirects in the following manner
Redirect 301 /oldpage /newpage