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

Clean Url settings

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 10-14-2014, 09:38 AM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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".
__________________
Ver 5.2.6
Reply With Quote
  #2  
Old 10-14-2014, 10:06 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following 3 users thank totaltec for this useful post:
Ksenia (10-14-2014), Phil Richman (10-15-2014), tony_sologubov (10-14-2014)
  #3  
Old 10-14-2014, 12:59 PM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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;
}
__________________
Ver 5.2.6
Reply With Quote
  #4  
Old 10-14-2014, 05:48 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following user thanks totaltec for this useful post:
Phil Richman (10-15-2014)
  #5  
Old 10-15-2014, 05:58 AM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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?
__________________
Ver 5.2.6
Reply With Quote
  #6  
Old 10-15-2014, 06:06 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
Phil Richman (10-15-2014)
  #7  
Old 10-15-2014, 06:43 AM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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.
__________________
Ver 5.2.6
Reply With Quote
  #8  
Old 10-15-2014, 06:59 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
Phil Richman (10-15-2014)
  #9  
Old 10-15-2014, 07:28 AM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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.
__________________
Ver 5.2.6
Reply With Quote
  #10  
Old 10-15-2014, 10:16 AM
 
Phil Richman Phil Richman is offline
 

Advanced Member
  
Join Date: May 2012
Posts: 94
 

Default 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.
__________________
Ver 5.2.6
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 01:37 AM.

   

 
X-Cart forums © 2001-2020