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


All times are GMT -8. The time now is 02:50 AM.

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