Zen Cart Logo
Forums / General Questions / 301 redirect from zencart urls to something else

301 redirect from zencart urls to something else

Views: 3,113

Results 1 to 14 of 14
3 Apr 2018, 3:10 PM
#1
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

301 redirect from zencart urls to something else

I am trying to do 301 redirects from individual zen cart pages via htaccess file.

Tried this but does not work.

#taking the url seen in browser
301 redirect /index.php?main_page=index&cPath=75 https://newdomain.com/product-category/pageexample/

#or taking the url from sitemap.xml
301 redirect /index.php?main_page=index&cPath=77 https://newdomain.com/product-category/anotherpage/

Any idea why not? I read so many versions on this forum that I am utterly confused on how to go about for redirecting a big list of urls. Not just a zencart domain or directory change, but a move to a whole different url structure from another cart.

3 Apr 2018, 3:50 PM
#2
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: 301 redirect from zencart urls to something else

I am no .htaccess guru, but it might help posting the entire contents of the file

3 Apr 2018, 4:12 PM
#3
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

Well, that's it for now. I just try to add one by one for now until I see what is working. I had the whole site done with 301's with above system only to realize that it is not functioning as with another zen cart site where I had ceon uri active. There it was a piece of cake with above pattern. These dynamic url's are giving me a hard time. Tried cpanel as well but only worked for the / directory. The rest fails with dynamic urls.

3 Apr 2018, 4:22 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 301 redirect from zencart urls to something else

A redirect is performed by first "announcing" that a redirect is to occur, then to provide the code that should be considered (30x) then from where/what to where/what as in:

redirect 302 /index.php?main_page=index&cPath=75 https://newdomain.com/productcategory/pageexample

Note though a couple of things:

  1. if the destination site is also a ZC site, then if the original database were used to generate that site's contents, all that would be necessary is a redirect from the one domain to the other.
  2. the sequence of redirects plays an important part, for example if cPath 75 and cPath 750 exist, then 750 will redirect to 75 if 75 is listed first.
  3. if the destination site is a ZC site as provided above then there are plugins that can provide human readable uris as presented in the example (though not described as necessary or really applicable.)
3 Apr 2018, 5:37 PM
#5
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

It is not going to another zencart site.

If I just put this in the .htaccess file, it does not redirect at all, just get's ignored. Does something else need to be put in it before hand?

#taking the url seen in browser
301 redirect /index.php?main_page=index&cPath=75 https://newdomain.com/product-category/pageexample/

3 Apr 2018, 6:10 PM
#6
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

After further searching and reading I found this example:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^(index.php)?$ http://www.example.com/? [R=301,L]

This is for a product, I need it for a category like my url example.

Found this article as well that shed some insight that the simple redirect 301 won't work for dynamic urls. https://www.goinflow.com/setting-up-301-redirects-for-dynamic-urls/

3 Apr 2018, 6:11 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 301 redirect from zencart urls to something else

mydanilo:

It is not going to another zencart site.

If I just put this in the .htaccess file, it does not redirect at all, just get's ignored. Does something else need to be put in it before hand?

#taking the url seen in browser
301 redirect /index.php?main_page=index&cPath=75 https://newdomain.com/product-category/pageexample/

I gave an example above, but let's try again.
This is what you have been trying that doesn't work:

#taking the url seen in browser
301 redirect /index.php?main_page=index&cPath=75 [url]https://newdomain.com/product-category/pageexample/[/url]

This is the format (sequence) I posted about:

#taking the url seen in browser
redirect 301 /index.php?main_page=index&cPath=75 [url]https://newdomain.com/product-category/pageexample/[/url]

Now, I used 302 instead of 301 in my example so that until you have things working like they should that nothing permanently caches an incorrect redirect. Once satisfied with the redirects, I would then change the 302 to 301.

3 Apr 2018, 6:27 PM
#8
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

301 or 302, not working. I think this is really due to the dynamic urls.

3 Apr 2018, 6:45 PM
#9
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 301 redirect from zencart urls to something else

mydanilo:

After further searching and reading I found this example:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=product_info&cPath=([0-9]+)&products_id=221$ [NC]
RewriteRule ^(index.php)?$ http://www.example.com/? [R=301,L]

This is for a product, I need it for a category like my url example.

Found this article as well that shed some insight that the simple redirect 301 won't work for dynamic urls. https://www.goinflow.com/setting-up-301-redirects-for-dynamic-urls/

Oh yeah, forgot about that aspect (I don't use redirect just knew the sequence was wrong):

RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=75$ [NC]
RewriteRule ^(index\.php)?$ [url]http://www.example.com/category/newpage?[/url] [R=301,L,NE]

Only one instance of rewriteengine on needs to be present before the first rewritecond and/or rewriterule.

3 Apr 2018, 6:50 PM
#10
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,097
Plugin Contributions:
56

Re: 301 redirect from zencart urls to something else

Perhaps if you'd post the current contents of your .htaccess file, that might shed some light on why it's not working.

3 Apr 2018, 7:56 PM
#11
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

lat9:

Perhaps if you'd post the current contents of your .htaccess file, that might shed some light on why it's not working.

I did. It's all I have there at the moment to test how I need to build the other links.

I will test this pattern and report back.
RewriteEngine On

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=75$ [NC]
RewriteRule ^(index.php)?$ http://www.example.com/category/newpage? [R=301,L,NE]

@mc12345678 and how would I add the general home page redirect old site to new site with this kind of code?
In the end I want old domain home page redirect to new domain home page. Then individually redirect some important pages from the old site to the new with already posted examples. Seems like too much work to do for all pages. At least I want to do a few that I get backlinks from.

3 Apr 2018, 9:03 PM
#12
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

OK, this works now.

I can with above code create individual redirects. In order to redirect the home page, I used cpanel to create a redirect. I merged the whole thing in one .htaccess an it is now working fine.

RewriteEngine On


RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/wholesale\.newdomain\-inc\.com\/" [R=301,L]

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=74$ [NC]
RewriteRule ^(index\.php)?$ https://wholesale.newdomain-inc.com/product-category/tin-star-lights? [R=301,L,NE]

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=75$ [NC]
RewriteRule ^(index\.php)?$ https://wholesale.newdomain-inc.com/product-category/moravian-glass-star-lights? [R=301,L,NE]

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=76$ [NC]
RewriteRule ^(index\.php)?$ https://wholesale.newdomain-inc.com/product-category/tin-stars-with-marbles? [R=301,L,NE]

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=77$ [NC]
RewriteRule ^(index\.php)?$https://wholesale.newdomain-inc.com/product-category/star-of-bethlehem? [R=301,L,NE]

RewriteCond %{QUERY_STRING} ^main_page=index&cPath=78$ [NC]
RewriteRule ^(index\.php)?$ https://wholesale.newdomain-inc.com/product-category/fiesta-stars? [R=301,L,NE]

RewriteCond %{QUERY_STRING} ^main_page=products_all$ [NC]
RewriteRule ^(index\.php)?$ https://wholesale.newdomain-inc.com? [R=301,L,NE]

Would be nice if there was a path to construct this with all urls from the old to new. On another zen cart with ceon uri installed, it was easy to do with the googlefeed.xml and then create the redirect in excel. Not sure how I could construct it with these dynamic links. But for now my most urgent redirects are done. Let me know if you think this code is not what I should be using. Thanks!

3 Apr 2018, 9:23 PM
#13
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 301 redirect from zencart urls to something else

So to be sure that it is understood about what was desired/what happened:

A new domain name was acquired and is on this server.

The previous domain name(s) that were hosted on this same server (or directed here now) are no longer providing content. The specific content from the previous domain(s) is now to be "accessible" at the new domain name.

If that is the case, also understand that the way the above htaccess is written that there will be a minimum of two redirects to get to the final content which is at least one more than necessary and is also discouraged.

The individual redirects already contain all of the information necessary to try to land on the correct final page for that redirect. Those should be identified and acted upon before redirecting the entire original domain(s). Doing so (placing the first grouping of rewriteCond/rewriteRule at the bottom will result in a single redirect for all links expected to be provided.

It's just a suggestion...

3 Apr 2018, 9:32 PM
#14
mydanilo avatar

mydanilo

Totally Zenned

Join Date:
Dec 2004
Posts:
1,024
Plugin Contributions:
0

Re: 301 redirect from zencart urls to something else

Great, I'll switch it around as you suggest. Thanks. Your statements are basically correct.

Yes old and new domain is hosted on the same server. BUT url structure has completely changed. Could not find an easy way to map them all. So just picking a few and also want the home page to redirect to new home page. If there is easier code to do the home page redirect and make the other individual redirects still work, I am open for suggestions. Just gave cpanel a try to add it.