redirect old url to new one in open cart - apache

I looking for some help to solve this issue. i'm using open cart and made a product long time ago, of course i'm used SEO url for this product.
Ex. example.com/myproduct
but now i decided to change this url:
Ex. example.com/newproduct
it's now working and up in new url but google indexed that old url and i trying to redirect that old url to new one but no success.
first i tried mod_rewrite:
RewriteRule ^myproduct$ https://example.com/newproduct [R=301,L]
it's not working, then write with old method, 301 redirect:
Redirect 301 /myproduct https://example.com/newproduct
it's look like redirected but there is a problem, when i run that old url it redirect to new url like this:
example.com/newproduct?route=myproduct
it show 404 page not found. but if i using fake url for example:
Redirect 301 /oldtest https://example.com/newtest
it's working fine! i'm wondering why it's not working!

I suggest this is because OpenCart is handling it and interfering with what you are doing. Use your first idea:
RewriteRule ^myproduct$ https://example.com/newproduct [R=301,L]
But make sure it is at the top of your .htaccess file before anything else from OpenCart. Make sure it has RewriteEngine On before it.

Related

htaccess 301 redirect for webshop transfer

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.

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

Drupal - Redirect just the homepage

due to internal politics with a project I need to redirect only the homepage of a site built in drupal to a different url. I want to be able to access the rest of the site to show people but just that when it goes to the homepage it redirects you.
I want to create a copy of the homepage and then have the original homepage automatically redirect to the new url....meta refresh wouldnt work because there is lag time...
Anyone know how to do this with .htaccess ?
Thanks
Add new comment
You can try adding this rule as first rule:
RewriteRule ^$ /new-home-page [L,R]

How to setup wild card 301 redirect that will remove URL parameters from index.php

ok I previously had some issues setting up a wild card redirect to strip parameters from an old url format that were non-seo friendly to our root. With the help of stackoverflow we've got it corrected and working but now I am experiencing issues with index.php?
Im seeing tons of duplicate urls in the engines using this url format index.php?cPath=# and Google is stressing me because they think its duplicate index pages.
I tried setting up this redirect in our htaccess but no go. It won't strip out the parameters or redirect it just duplicates the page with a valid 200 response.
RewriteRule ^index.php/.*$ /? [R=301,NE,NC,L]
I want to redirect anything with index.php?cPath=# to our root domain. Any ideas on how i can tackle this 301 redirect using a mod_rewrite on apache?
I've also just noticed that our site has another issue with this url format:
domain.com/?cPath=#...
so now I also need to write a rewrite for domain.com/?cPath=# I don't know where this one popped up from but I can see its going to cause issues hence the valid 200 response code it gives. The engines are really going to love me for this one.

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