X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   301 Redirect not working in HTACCESS file (https://forum.x-cart.com/showthread.php?t=73147)

ant99 11-24-2015 04:59 PM

301 Redirect not working in HTACCESS file
 
We have a list of 301 redirects in the .htaccess file. They are simple rules written one on each line as so:

PHP Code:

Redirect 301 /old-urlhttps://domain.com/new-url.htm
Redirect 301 /another-urlhttps://domain.com/destination/ 


These URLs are resolving like this and returning a 404 Page Not Found error:
Code:

https://domain.com/new-url.htm?url=old-url&last=&rest=&ext=
https://domain.com/destination/?url=another-url&last=&rest=&ext=


They seem to be redirecting properly and the final URL would be fine if the page wasn't 404'd. It looks like there is a rule in x-carts .htaccess file that appends a string to the URL if a certain file or directory does not exist from the URL.

PHP Code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(/?)(\.([_a-z0-9-]+))?$ cart.php?url=$5&last=$4&rest=$3&ext=$[NC,L,QSA


What is the purpose of this rewrite? More importantly, how can I make the 301 Redirect rules work properly? Should I be trying a different route? Please help as this is urgent. Any insight is much appreciated. Thanks in advance.

razortw 11-26-2015 04:50 AM

Re: 301 Redirect not working in HTACCESS file
 
These are for proper functioning of clean URLs.
* http://kb.x-cart.com/display/XDD/Setting+up+seo-friendly+URLs

ant99 11-26-2015 06:16 AM

Re: 301 Redirect not working in HTACCESS file
 
Igor,

Thanks for your reply. I understand that's what the rules are for, but that really doesn't help answer my question.

How can I get the "Redirect 301" rules to work properly? Do you have any insight?

What is the proper way add redirect rules to x-cart? Why are these pages not resolving when there is the query string at the end?

razortw 11-27-2015 12:06 PM

Re: 301 Redirect not working in HTACCESS file
 
Try something like that
Code:

RewriteRule  ^all\-products\/category(.*) "https\:\/\/www\.yoursite\.com\/all\-products\/category" [R=301,L]
This should work

ant99 12-02-2015 01:10 PM

Re: 301 Redirect not working in HTACCESS file
 
Igor, this is perfect. I converted all of the redirects to that format and everything appears to be working great. Thanks for the suggestion.

razortw 12-07-2015 07:34 AM

Re: 301 Redirect not working in HTACCESS file
 
Quote:

Originally Posted by ant99
Igor, this is perfect. I converted all of the redirects to that format and everything appears to be working great. Thanks for the suggestion.

You're welcome!
Glad I could help :)

mgwashburn 07-23-2016 09:34 PM

Re: 301 Redirect not working in HTACCESS file
 
Please help,

having the same issue as the above poster.

on all of my x-cart 4.x installs the standard Redirect 301 always has worked well.

but in 5.2 it appends this strange stuff that makes the redirect fail.

I have attempted to use:

RewriteRule ^all\-products\/category(.*) "https\:\/\/www\.yoursite\.com\/all\-products\/category" [R=301,L]
but is does not work for me.

I am trying to re-point several directories for example:

www.naturalbathbody.com/bath/bath-and-shower/

which now is:

www.naturalbathbody.com/bath-and-shower/

the above code snipped may work well with .html pages, but I have tried multiple ways to format changing categories and it just will not work.

can someone please post an example instead of the code snippet?

that would really help.

thanks in advance,

Marc W.

razortw 07-25-2016 03:13 AM

Re: 301 Redirect not working in HTACCESS file
 
Could you please post here the exact rewrite rule that isn't working?

mgwashburn 07-25-2016 10:05 PM

Re: 301 Redirect not working in HTACCESS file
 
Quote:

Originally Posted by razortw
Could you please post here the exact rewrite rule that isn't working?

Certainly

This is a very normal 301 redirect:

.htaccess last line:

Redirect 301 /Natural-Shaving-Gel.html https://www.naturalbathbody.com/apollon-shaving-gel.html

The redirect is picked up and if you go to page:

http://www.naturalbathbody.com/Natural-Shaving-Gel.html

the it jumps to this page:

https://www.naturalbathbody.com/apollon-shaving-gel.html?url=Natural-Shaving-Gel&last=&rest=&ext=.html

but of course this page does not exist and the extra garbage that is appended causes a 404 error.

please help ... maybe you can show me an example of how that 301 code above has to be structured in X-cart 5.2.15...

thank you in advance

Marc

cflsystems 07-26-2016 07:30 AM

Re: 301 Redirect not working in HTACCESS file
 
I would try with the dynamic url instead

Redirect 301 /Natural-Shaving-Gel.html https://www.naturalbathbody.com/cart.php?target=product&productid=XX

example for a product page

mgwashburn 07-26-2016 07:40 AM

Re: 301 Redirect not working in HTACCESS file
 
Thank you, that worked...

I actually went to the page and noticed that by default after clicking on the link after finding it during an on page search I got this:

https://www.naturalbathbody.com/apollon-shaving-gel.html?category_id=24

I then added the '?category_id=24' to the 301 redirect statement and then it worked.

So I assume your idea of putting in the product id number would also work.

thank you so much for you help,

very much appreciated,

Marc W.

cflsystems 07-26-2016 07:54 AM

Re: 301 Redirect not working in HTACCESS file
 
You don't want to do this really. The way XC adds this extra to the html url is really ugly and I wouldn't want my urls indexed like that. Use the target=product version instead so you can get a clean html url.

kevinrm 07-27-2016 02:01 AM

Re: 301 Redirect not working in HTACCESS file
 
If you want to simplify your life, there is a pretty good redirect module for XC5. I've been using it, I like it.

qualiteam 07-27-2016 04:35 AM

Re: 301 Redirect not working in HTACCESS file
 
Quote:

Originally Posted by mgwashburn
I actually went to the page and noticed that by default after clicking on the link after finding it during an on page search I got this:

https://www.naturalbathbody.com/apollon-shaving-gel.html?category_id=24

I then added the '?category_id=24' to the 301 redirect statement and then it worked.


I guess the product is added to a number of categories at the same time, that's why XC5 adds an extra param to track which category you came from to the page.

It should work without the category_id param as well (moreover, the "canonical" meta tag has no the parameter).

But what Steve says is a different thing. He advises you not to add product_id to the tail of your clean URL, but replace "appolon-shaving-gel.html" with the non-cleanURL version (?target=product&product_id=...).
This makes sense as after all rewrites the script works with this version of the URL anyway.

Quote:

Originally Posted by kevinrm
If you want to simplify your life, there is a pretty good redirect module for XC5. I've been using it, I like it.



I guess you mean this third-party module:
http://market.x-cart.com/addons/xcart-redirects-by-Nova-Horizons.html


All times are GMT -8. The time now is 09:15 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.