Products - remove the id/category from the product URL slug

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
radiosilence
New Member
New Member
Posts: 2
Joined: Thu Feb 24, 2011 12:33 am

Products - remove the id/category from the product URL slug

Post by radiosilence »

I've got version 2.10.3 installed. When I create a product, I'm getting a URL slug like this:

Code: Select all

http://www.domain.com/products/1/34/test-product-1
Is there a way to remove the "1/34" (what I assume to be the product ID and Category ID) from the URL and have it look like

Code: Select all

http://www.domain.com/products/test-product-1
Thanks in advance!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Products - remove the id/category from the product URL s

Post by calguy1000 »

At Present. No. The product ID, and the Page ID have to be somewhere on the URL.

There is a method that I can implement to remove them, however I have not had the time to do that of late. It will probably be a few more months before I can get to it, unless somebody wants to sponsor the modification.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
radiosilence
New Member
New Member
Posts: 2
Joined: Thu Feb 24, 2011 12:33 am

Re: Products - remove the id/category from the product URL s

Post by radiosilence »

Might be interested in that. Let me know what I'd need to do to pursue that option.
proboscidian
Forum Members
Forum Members
Posts: 23
Joined: Sun Feb 24, 2008 11:12 pm

Re: Products - remove the id/category from the product URL s

Post by proboscidian »

Has there been any update on this?
peterbisset

Re: Products - remove the id/category from the product URL s

Post by peterbisset »

Is it still not possible to do this?
Peciura

Re: Products - remove the id/category from the product URL s

Post by Peciura »

General practice is to include both product ID and product alias to url. Lets say we have a product ID 123456.
Urls might look like

Code: Select all

www.hostname.com/p123456_product_alias
www.hostname.com/123456/product_alias
www.hostname.com/product_alias_123456
So if it is good enough for you you can create your own links

Code: Select all

/p{$entry->id}_{$entry->alias}
And add couple of lines to ".htaccess"
<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^p([\d]+)_ index.php?mact=Products,cntnt01,details,0&cntnt01productid=$1 [QSA]
</IfModule>
peterbisset

Re: Products - remove the id/category from the product URL s

Post by peterbisset »

Thank you for your reply. So if I wanted to change my product urls to "http://www.domain.com/name-of-product/ for instance how would I modify my .htaccess file below?

Code: Select all

AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

# Attempt to override some php settings, these settings may be helpful on some hosts if your
# default configuration does not meet CMS's minimum requirements, and your host
# has given your account appropriate permissions
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# (this is important, so uncomment if your host permit)
#Options -Indexes
#ServerSignature Off

#Options +FollowSymLinks
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] 

# To prevend E_STRICT problems with PHP 5.3+ you can uncomment the following lines
# Note: These settings should only be enabled for production sites!
#php_flag display_startup_errors 0
#php_flag display_errors 0
#php_flag html_errors 0
#php_value docref_root 0
#php_value docref_ext 0

<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

</IfModule>

<IfModule mod_header.c>
# Disable ETags
Header unset ETag
FileEtag None
</IfModule>

<IfModule mod_deflate.c>
# Compress css, plaintext, xml, gif, and images in transport.
AddOutputFilterByType DEFLATE text/css text/plain text/xml image/gif image/jpeg image/png
</IfModule>

<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
# Set expires tags on various files... so that the browser wont attempt to reload them.
ExpiresActive On
ExpiresDefault "access plus 1 year"
<IfModule mod_header.c>
  # Setting cache control to public allowes proxy servers to cache the items too.
  Header set Cache-Control "public"
</IfModule>
</FilesMatch>
</IfModule>
Last edited by Dr.CSS on Fri Mar 16, 2012 6:10 pm, edited 1 time in total.
Reason: Please use double quotes on fake links so they aren't clickable...
Peciura

Re: Products - remove the id/category from the product URL s

Post by Peciura »

You can use product alias, not product name.

Your rewrite rules could look similar to these

Code: Select all

RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

#display valid content pages: "shipping" or "about-us"
RewriteCond %{REQUEST_URI} ^/(shipping|about-us)(\?.+)*
RewriteRule ^(.+)$ /index.php?page=$1 [QSA,L]

#anything else is supposed to be product alias 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.+)/$ index.php?mact=Products,cntnt01,details,0&cntnt01alias=$1 [QSA,L]
Last edited by Peciura on Mon Apr 09, 2012 9:32 pm, edited 1 time in total.
peterbisset

Re: Products - remove the id/category from the product URL s

Post by peterbisset »

Thank you that works perfectly for generating the urls that I want. The only problem is that my {products} tag does not recognise any of the products now, even though they can be accessed by typing the url directly into the browser. Can you think of a reason why?
Peciura

Re: Products - remove the id/category from the product URL s

Post by Peciura »

...The only problem is that my {products} tag does not recognise any of the products...
Can you post link and explain in detail.
Post Reply

Return to “Modules/Add-Ons”