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)
-   -   Clean Url settings (https://forum.x-cart.com/showthread.php?t=70243)

Phil Richman 10-14-2014 09:38 AM

Clean Url settings
 
Looking to start using xcart 5, but having trouble with clean urls. I am trying to figure out how to adjust clean url settings in xcart 5. The clean urls are using ".html", and I would prefer to use "/" so as to keep page names consistent with my existing site. How would I go about changing this? Just to make sure what I'm asking is clear I want "example.com/page/" instead of "example.com/page.html".

totaltec 10-14-2014 10:06 AM

Re: Clean Url settings
 
Phil,
I think I have found the class you would need to decorate. Take a look at classes/XLite/Core/Converter.php function buildCleanURL

This line in particular: $urlParams[] = $product->getCleanURL() . '.html';

Try changing that to a / instead of .html

Of course, don't modify the core file, decorate it in your module.

Phil Richman 10-14-2014 12:59 PM

Re: Clean Url settings
 
Quote:

Originally Posted by totaltec
Phil,
I think I have found the class you would need to decorate. Take a look at classes/XLite/Core/Converter.php function buildCleanURL

This line in particular: $urlParams[] = $product->getCleanURL() . '.html';

Try changing that to a / instead of .html

Of course, don't modify the core file, decorate it in your module.

I made an attempt at your suggestion, but I'm very new to xcart 5, and not sure if I did this correctly. Below is an example of my Converter.php file. I added this and redeployed the store. I don't see any problems, but it doesn't appear to have changed the clean url. Can you take a look at my code below, and see what you think?


<?php


namespace XLite\Module\Pmall\PmallSkin\Core;


abstract class Converter extends \XLite\Core\Converter implements \XLite\Base\IDecorator

public static function buildCleanURL($target = '', $action = '', array $params = array())
{
$result = null;
$urlParams = array();

if ('product' === $target && empty($action) && !empty($params['product_id'])) {
$product = \XLite\Core\Database::getRepo('\XLite\Model\Produc t')->find($params['product_id']);
if (isset($product) && $product->getCleanURL()) {
$urlParams[] = $product->getCleanURL() . '/';
unset($params['product_id']);
}
}

if (
('category' === $target || ('product' === $target && !empty($urlParams)))
&& empty($action)
&& !empty($params['category_id'])
) {
$category = \XLite\Core\Database::getRepo('\XLite\Model\Catego ry')->find($params['category_id']);
if (isset($category) && $category->getCleanURL()) {
foreach (array_reverse($category->getPath()) as $node) {
if ($node->getCleanURL()) {
$urlParams[] = $node->getCleanURL();
}
}
}

if (!empty($urlParams)) {
unset($params['category_id']);
}
}

static::buildCleanURLHook($target, $action, $params, $urlParams);

if (!empty($urlParams)) {
unset($params['target']);
$result = implode('/', array_reverse($urlParams));
if (!empty($params)) {
$result .= '?' . http_build_query($params);
}
}

return $result;
}

totaltec 10-14-2014 05:48 PM

Re: Clean Url settings
 
Phil,
The only thing I see that I don't understand is the abstract declaration.
It also looks like you are missing defining {} brackets around your class itself.

abstract class Converter extends \XLite\Core\Converter implements \XLite\Base\IDecorator
{
Function goes here
}

Other obvious questions are, is this module activated? is it functioning in other ways?

So, I investigated this and was able to successfully change .html to .htm

But when I tried to change it to / it failed 404 error not found. So I think some .htaccess magic is needed in addition to this change.

Phil Richman 10-15-2014 05:58 AM

Re: Clean Url settings
 
Quote:

Originally Posted by totaltec
Phil,
The only thing I see that I don't understand is the abstract declaration.
It also looks like you are missing defining {} brackets around your class itself.

abstract class Converter extends \XLite\Core\Converter implements \XLite\Base\IDecorator
{
Function goes here
}

Other obvious questions are, is this module activated? is it functioning in other ways?

So, I investigated this and was able to successfully change .html to .htm

But when I tried to change it to / it failed 404 error not found. So I think some .htaccess magic is needed in addition to this change.

Thank you very much for your help with this. Your suggestions and advice have been awesome. I added the missing defining brackets and redeployed. Like you I tried .htm just to make sure it was working. this worked fine, so I switched it to the / and like you I got the 404 error. I have been messing with the .htaccess but not having much luck. Is this something you might be able to offer some help with?

cflsystems 10-15-2014 06:06 AM

Re: Clean Url settings
 
This '/' may be getting in the way of non-.html urls - so there is probably another piece of code to add '/' if it is not product... it may not be htacess issue.

On the other hand there is this in htaccess

Code:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule (^|/)\. - [F]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(htm|html))?$ cart.php?url=$5&last=$4&rest=$3&ext=$7 [NC,L,QSA]

  RewriteBase /xcart-devs/xc5
</IfModule>


which works on non-folder and non-directory and with htm or html extensions only. Have you tried any other extension like .hhh to see if it works - if it doesn't then it is definitely this line in htaccess

Phil Richman 10-15-2014 06:43 AM

Re: Clean Url settings
 
Quote:

Originally Posted by cflsystems
This '/' may be getting in the way of non-.html urls - so there is probably another piece of code to add '/' if it is not product... it may not be htacess issue.

On the other hand there is this in htaccess

Code:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule (^|/)\. - [F]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(htm|html))?$ cart.php?url=$5&last=$4&rest=$3&ext=$7 [NC,L,QSA]

  RewriteBase /xcart-devs/xc5
</IfModule>


which works on non-folder and non-directory and with htm or html extensions only. Have you tried any other extension like .hhh to see if it works - if it doesn't then it is definitely this line in htaccess

I tried your test of switching extension to .hhh. I received the 404 just like when I was using the '/' . The lines above from the htaccess that you referenced are the ones I have been editing to try and get this to work, but I'm not very well versed in mod_rewrite. Do you have any suggestions on how to make this work for me? I'm also in the process of trying to figure out how to fix the clean urls for category. Currently the category clean urls are 'example.com/category/subcategory1/subcategory2/' and I would like for only the category / subcategory that you are in to show. I'm looking for something more like example.com/subcategory2.

cflsystems 10-15-2014 06:59 AM

Re: Clean Url settings
 
The line

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(htm|html))?$ cart.php?url=$5&last=$4&rest

looks for only htm and html to rewrite url. You can try adding hhh to see if it will work - if it does it is definitely this rul

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(hhh|htm|html))?$ cart.php?url=$5&last=$4&rest

You can also try

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(\/|htm|html))?$ cart.php?url=$5&last=$4&rest

for the / but I am guessing this may get in the way of categories, not sure

Phil Richman 10-15-2014 07:28 AM

Re: Clean Url settings
 
Quote:

Originally Posted by cflsystems
The line

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(htm|html))?$ cart.php?url=$5&last=$4&rest

looks for only htm and html to rewrite url. You can try adding hhh to see if it will work - if it does it is definitely this rul

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(hhh|htm|html))?$ cart.php?url=$5&last=$4&rest

You can also try

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(\/|htm|html))?$ cart.php?url=$5&last=$4&rest

for the / but I am guessing this may get in the way of categories, not sure

I tried your htaccess edit with .hhh and it worked. When I tried the change for / it returned a 404.

Phil Richman 10-15-2014 10:16 AM

Re: Clean Url settings
 
Quote:

Originally Posted by cflsystems
The line

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(htm|html))?$ cart.php?url=$5&last=$4&rest

looks for only htm and html to rewrite url. You can try adding hhh to see if it will work - if it does it is definitely this rul

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(hhh|htm|html))?$ cart.php?url=$5&last=$4&rest

You can also try

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\.(\/|htm|html))?$ cart.php?url=$5&last=$4&rest

for the / but I am guessing this may get in the way of categories, not sure

I got this working for products now.

Here is the RewriteRule I used:

RewriteRule ^((([/_a-z0-9-]+)/)?([_a-z0-9-]+)/)?([_a-z0-9-]+)(\/)?$ cart.php?url=$5&last=$4&rest=$3&ext=$7 [NC,L,QSA]

I'm still working on the categories if anyone has any suggestions on this.

A BIG THANK YOU to Mike and Steve for all of your help so far. You guys have been a huge help.


All times are GMT -8. The time now is 04:22 AM.

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