SEO: remove .html

Hello,



I’d like to know how to remove the .html from the links so that products show as:



[url]http://www.mydomain.com/product[/url] instead of [url]http://www.mydomain.com/product.html[/url]



I have the SEO addon active but it doesn’t offer that choice.



Has any of you done it?



Thank you.

you could just do it with a rewrite , but before you go do that, why on earth would you want to remove a file extension for SEO, to make a se wonder if it that is image or pdf or script??



don’t do this - its not a good idea… and that is coming from an SEO

Hi xmivite,



Mainly so that people can quote the url in marketing materials and there’s no risk of people missing the .html part.



Thank you for your thoughts. I’m using .htaccess rewrite, but I rather have a way of doing it through the backend. It was possible in the previous version.



Cheers,



Pedro

i am too request for remove.html on seo. anybody knows?

Maybe I am used to wordpress style seo urls (without the html) so I hack some code to remove the .html also.



Please note that I did this by hacking the seo addon func.php code, so whenever upgrading, you need to resolve if any, conflicts due to the modifying of code (if you use the code).



In root/addons/seo/func.php

look for the line with the first occurrence of:


$seo_name = $seo_name . '.html';


Or more correctly, within the “if ($object_type == ‘p’) {” statement.

modify it to:


//$seo_name = $seo_name . '.html'; //edited by yourname
$seo_name = $seo_name;






Next, look for the line of code


if ((in_array($seo['type'], array('p', 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') == 'category' && !empty($objects['extension']))) {
$result = false;
}


comment off the ‘p’ inside the array brackets, so that it looks like this


//edited by yourname to remove p=product check for html
if ((in_array($seo['type'], array(/*'p',*/ 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') == 'category' && !empty($objects['extension']))) {
$result = false;
}




Your products URL should be generated without the html now.



I add acomment to all my modified code with my username or a special word, to indicate that I’ve made changes to that line of code. It is easier to search for all changes made by me using the username/special word in future if I need to resolve conflicts.

nodame thank you so much, i wonder if you did the same for category.html, and others? so its all without .html

For categories, you can set the setting via the addons>seo>edit settings.

Under “Category SEF URL format:”, choose the 2nd or 3rd option, to have URLs without the html.

nodame thanks a lot pal :slight_smile:

@nodame Thanks for all your help! The categoy file extension is removed, but the code above that does not seem to work. Is there an updated fix?

I, too, am curious if anyone is able to offer an updated solution to this… they changed the /addons/seo/func.php file and it no longer is editable in the same way as before.

Okay, I figured it out.



In /addons/seo/func.php, on line 453, change it to:


// check for .html extension for the current object
if ((in_array($seo['type'], array(/*'p',*/ 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {
$result = false;
}




then in /addons/seo/init.php, on line 22, change it to:


fn_define('SEO_FILENAME_EXTENSION', '');

[quote name='trevorgehman' timestamp='1309806773' post='116249']

Okay, I figured it out.



In /addons/seo/func.php, on line 453, change it to:


// check for .html extension for the current object
if ((in_array($seo['type'], array(/*'p',*/ 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {
$result = false;
}




then in /addons/seo/init.php, on line 22, change it to:


fn_define('SEO_FILENAME_EXTENSION', '');

[/quote]



But how did you get “site news” and “about-us.html” pages to work?

Thanks a lot that seemed to work for products but it broke all my pages. It shows them as www.domains.com/about/ but gives a 404. Any ideas?



Thanks again.


[quote name='trevorgehman' timestamp='1309806773' post='116249']

Okay, I figured it out.



In /addons/seo/func.php, on line 453, change it to:


// check for .html extension for the current object
if ((in_array($seo['type'], array(/*'p',*/ 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {
$result = false;
}




then in /addons/seo/init.php, on line 22, change it to:


fn_define('SEO_FILENAME_EXTENSION', '');

[/quote]

I do it, but after this, all my pages do'nt work. I repaer like this I chang false on true ) and all work;)
// check for .html extension for the current object
if ((in_array($seo['type'], array(/*'p',*/ 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {
$result = true;
}

Fix for 3.0.3



//addons/seo/func.php [Line 188]



Find the following code:

$condition .= db_quote(' OR ?:seo_names.name LIKE ?s', '%' . preg_replace('/-[a-zA-Z]{1,3}$/i', '', str_ireplace('.html', '', $params['q'])) . '%');



Replace with:

$condition .= db_quote(' OR ?:seo_names.name LIKE ?s', '%' . preg_replace('/-[a-zA-Z]{1,3}$/i', '', str_ireplace('', '', $params['q'])) . '%');

-------------------------------------------------------------------------------



Find the following code [Line 722]

if ((in_array($seo['type'], array('p', 'a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {



Replace with:

if ((in_array($seo['type'], array('a')) && empty($objects['extension'])) || ($seo['type'] == 'c' && Registry::get('addons.seo.seo_category_type') != 'file' && !empty($objects['extension']))) {

edit: fixed

Hello will the above fix work on CS CART 4.XX ?

On file [color=#ff0000]app/addons/seo/func.php [/color]


  1. after (starting line:810)
    $vars = fn_get_seo_vars($seo['type']);
    $id_path = '';
    if ($seo['type'] == 'p') {
    if (Registry::get('addons.seo.seo_product_type') == 'product_category') {
    add
    $objects['extension'] = SEO_FILENAME_EXTENSION; //added by Valentin | hungryweb.net



  2. replace (line:1437)
    $link_parts['extension'] = SEO_FILENAME_EXTENSION;
    with
    $link_parts['extension'] = ''; //modified, SEO_FILENAME_EXTENSION




    or search for
    // Convert products links
    if ($parced_query['dispatch'] == 'products.view' && !empty($parced_query['product_id'])) {
    if ($seo_settings['seo_product_type'] == 'product_category') {
    $parent_item_names = fn_seo_get_parent_items_path('p', $parced_query['product_id'], false, $company_id_in_url, $lang_code);
    $link_parts['parent_items_names'] = !empty($parent_item_names) ? join('/', $parent_item_names) . "/" : "";
    }
    $link_parts['name'] = fn_seo_get_name('p', $parced_query['product_id'], '', $company_id_in_url, $lang_code);
    $link_parts['extension'] = SEO_FILENAME_EXTENSION;
    and replace
    $link_parts['extension'] = SEO_FILENAME_EXTENSION;
    with
    $link_parts['extension'] = ''; //modified, SEO_FILENAME_EXTENSION








    Valentin

    [color=#808080][size=2]part of hungryweb.net[/size][/color]

Removing the “.html” was one of the first things we did around 3 years ago ,when switching to CS Cart. It hasn't affected our SEO at all.


[quote name='xmivite' timestamp='1260529717' post='63856']

you could just do it with a rewrite , but before you go do that, why on earth would you want to remove a file extension for SEO, to make a se wonder if it that is image or pdf or script??



don't do this - its not a good idea… and that is coming from an SEO

[/quote]

For removing the / at the end of categories, look for:



if ($seo_settings['seo_category_type'] != 'file') {

$link_parts['name'] .= '/';



Replace:



$link_parts['name'] .= '/';



with:



$link_parts['name'] .= ''; //modified by Vic, removes / from links



This is very usefull if you are using nginx servers(much faster responses compared with Apache, on my case nginx doubled the performance):



Add this to your server nginx directives(or direct to your nginx configuration file /etc/nginx/nginx.conf or /conf/vhost_nginx.conf)

location /$ {

index index.php;

try_files $uri $uri/ /index.php?sef_rewrite=1&$args;

}