Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

301 Redirect not working in HTACCESS file

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-24-2015, 04:59 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Exclamation 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.
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #2  
Old 11-26-2015, 04:50 AM
  razortw's Avatar 
razortw razortw is offline
 

X-Cart team
  
Join Date: Feb 2015
Posts: 807
 

Default 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
__________________
Best regards,
Igor Pudovkin
X-Cart hosting team
Reply With Quote
  #3  
Old 11-26-2015, 06:16 AM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default 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?
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote
  #4  
Old 11-27-2015, 12:06 PM
  razortw's Avatar 
razortw razortw is offline
 

X-Cart team
  
Join Date: Feb 2015
Posts: 807
 

Default 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
__________________
Best regards,
Igor Pudovkin
X-Cart hosting team
Reply With Quote
  #5  
Old 12-02-2015, 01:10 PM
 
ant99 ant99 is offline
 

Advanced Member
  
Join Date: Mar 2015
Posts: 39
 

Default 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.
__________________
Ant

XC v5.3.1.8
Horizontal Flyout Categories Menu Module
CloudSearch / CloudFilters

XC v4.7.6
CloudSearch
Reply With Quote

The following user thanks ant99 for this useful post:
razortw (12-07-2015)
  #6  
Old 12-07-2015, 07:34 AM
  razortw's Avatar 
razortw razortw is offline
 

X-Cart team
  
Join Date: Feb 2015
Posts: 807
 

Default 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
__________________
Best regards,
Igor Pudovkin
X-Cart hosting team
Reply With Quote
  #7  
Old 07-23-2016, 09:34 PM
 
mgwashburn mgwashburn is offline
 

Advanced Member
  
Join Date: Sep 2013
Posts: 78
 

Default 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.
__________________
Marc Washburn
www.EverythingGraphic.com
Running four successful X-cart 5.3.x installations and one 5.4.x
Reply With Quote
  #8  
Old 07-25-2016, 03:13 AM
  razortw's Avatar 
razortw razortw is offline
 

X-Cart team
  
Join Date: Feb 2015
Posts: 807
 

Default Re: 301 Redirect not working in HTACCESS file

Could you please post here the exact rewrite rule that isn't working?
__________________
Best regards,
Igor Pudovkin
X-Cart hosting team
Reply With Quote
  #9  
Old 07-25-2016, 10:05 PM
 
mgwashburn mgwashburn is offline
 

Advanced Member
  
Join Date: Sep 2013
Posts: 78
 

Default 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
__________________
Marc Washburn
www.EverythingGraphic.com
Running four successful X-cart 5.3.x installations and one 5.4.x
Reply With Quote
  #10  
Old 07-26-2016, 07:30 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,024
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:52 PM.

   

 
X-Cart forums © 2001-2020