Page 1 of 2
Pretty URL's for News Category Browse Links?
Posted: Wed Jan 28, 2009 11:12 am
by The Peckham Plater
Searching for a way to change the News Category links to be a bit more readable, not much luck unfortunately.
Anybody have any handy tips for this?
Code: Select all
{news sortby="news_category" browsecat="1"}
produces links like:
Code: Select all
index.php?mact=News,cntnt01,default,0&cntnt01sortby=news_category&cntnt01sortasc=true&cntnt01detailpage=&cntnt01category_id=13&cntnt01returnid=15
Many thanks if you can help.
Re: Pretty URL's for News Category Browse Links?
Posted: Mon Dec 20, 2010 9:46 pm
by Owens
Sorry to be so late with a response, but I did this with a UDT and a modification to my .htaccess file.
First I created a UDT called
news_category_url
Code: Select all
$name = preg_replace(array("/ /", "/[^A-Za-z0-9-\-]/", "/--/"),array("-", "", "-"),$params['name']);
$id = $params['id'];
echo 'blog/category/'.$id.'/'.$name.'.htm';
You will need to change the
.htm in the code above to whatever extension you are using on your site.
Then edit your News Category Template.
Find:
Code: Select all
{if $node.count > 0}
<a href="{$node.url}">{$node.news_category_name}</a> ({$node.count}){else}<span>{$node.news_category_name} (0)</span>{/if}
Change it to:
Code: Select all
{if $node.count > 0}
<a href="{news_category_url name=$node.news_category_name id=$node.news_category_id}">{$node.news_category_name}</a> ({$node.count}){else}<span>{$node.news_category_name} (0)</span>{/if}
Finally add a line like this to your .htaccess file before the CMSMS rewrite rules that add the trailing slash (or extension) and the page rewrite rule:
Code: Select all
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^news/category/([0-9]+)/(.+).htm index.php?mact=News,cntnt01,default,0&cntnt01detailpage=15&cntnt01category_id=$1&cntnt01returnid=15 [NC,L]
In the above code you will need to change the
.htm to whatever extension you are using for your site. You will also need to change the
detailpage=15 and
returnid=15 to the id of the page you want the listings to be displayed on. You may also need to change the
news/category... to match the links you are building (see questions and answers below for an
example .htaccess file).
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Aug 04, 2011 3:47 pm
by swarfega
Apologies in brining up an old thread.
I followed the instructions given in the response below, and while the categories are prettified, when you click on them, they dont work.
Re: Pretty URL's for News Category Browse Links?
Posted: Fri Aug 05, 2011 1:46 am
by Owens
swarfega wrote:I followed the instructions given in the response below, and while the categories are prettified, when you click on them, they dont work.
If you are asking for help. We will need much more information, such as, your code (from both the .htaccess file and the UDT), and a link to your site would be helpful. This will allow someone in the community to try and assist you.
The code I submitted in my previous post works perfectly fine, examples (proof of the pudding is in the eating):
Re: Pretty URL's for News Category Browse Links?
Posted: Fri Aug 05, 2011 8:23 am
by swarfega
Thanks for your reply and here is the info.
Site:
http://thriplow.org.uk
news_category_url
Code: Select all
$name = preg_replace(array("/ /", "/[^A-Za-z0-9-\-]/", "/--/"),array("-", "", "-"),$params['name']);
$id = $params['id'];
echo 'category/'.$id.'/'.$name.'.pc';
News Category Template
Code: Select all
{if $count > 0}
<ul class="list1">
{foreach from=$cats item=node}
{if $node.depth > $node.prevdepth}
{repeat string="<ul>" times=$node.depth-$node.prevdepth}
{elseif $node.depth < $node.prevdepth}
{repeat string="</li></ul>" times=$node.prevdepth-$node.depth}
</li>
{elseif $node.index > 0}</li>
{/if}
<li class="newscategory">
{if $node.count > 0}
<a href="{news_category_url name=$node.news_category_name id=$node.news_category_id}">{$node.news_category_name}</a> ({$node.count}){else}<span>{$node.news_category_name} (0)</span>{/if}
{/foreach}
{repeat string="</li></ul>" times=$node.depth-1}</li>
</ul>
{/if}
htaccess file
Code: Select all
ErrorDocument 404 /cms/index.php?page=error404
RemoveHandler .php
AddType application/php5-fcgi php
Action application/php5-fcgi /cgi-bin/php5fcgi.fcgi
<IfModule php5_module>
php_value include_path /ZendGdata
</IfModule>
# ------------------------
# BEGIN Optional settings
Options -Indexes
Options +FollowSymLinks
DirectoryIndex /cms/index.php
RewriteBase /cms
RewriteEngine on
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# except for form POSTS
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 ^(.+).pc$ index.php?page=$1 [QSA]
#RewriteRule ^cms/(.+)$ http://thriplow.org.uk/cms/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} ^thriplow.org.uk$ [OR]
#RewriteCond %{HTTP_HOST} ^www.thriplow.org.uk$
# News Pretty URL Fix
#RewriteRule ^news/([^/][0-9]+)/([^/][0-9]+)/(.+)$ #index.php?mact=News,cntnt01,detail,0&cntnt01articleid=$1&cntnt01returnid=$2 [NC,L]
#RewriteCond %{HTTP_HOST} ^thriplow.org.uk$ [OR]
#RewriteCond %{HTTP_HOST} ^www.thriplow.org.uk$
#RewriteRule ^news/category/([0-9]+)/(.+).pc #index.php?mact=News,cntnt01,default,0&cntnt01detailpage=59&cntnt01category_id=$1&cntnt01returnid=59 [NC,L]
RewriteCond %{HTTP_HOST} ^thriplow.org.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.thriplow.org.uk$
RewriteRule ^news/category/([0-9]+)/(.+).pc index.php?mact=News,cntnt01,default,0&cntnt01detailpage=59&cntnt01category_id=$1&cntnt01returnid=59 [NC,L]
Re: Pretty URL's for News Category Browse Links?
Posted: Fri Aug 05, 2011 2:08 pm
by Owens
You need to make some changes in your .htaccess file. (1) Remove the news/ from the rewrite rule and replace it with cms/; as you are not using news in your URL hierarchy. (2) put the news category rewrite rule before the two CMSMS rewrite rules; the trailing character and page rewrite. Try this instead as your .htaccess file...
Code: Select all
ErrorDocument 404 /cms/index.php?page=error404
RemoveHandler .php
AddType application/php5-fcgi php
Action application/php5-fcgi /cgi-bin/php5fcgi.fcgi
<IfModule php5_module>
php_value include_path /ZendGdata
</IfModule>
# ------------------------
# BEGIN Optional settings
Options -Indexes
Options +FollowSymLinks
DirectoryIndex /cms/index.php
RewriteBase /cms
RewriteEngine on
RewriteCond %{HTTP_HOST} ^thriplow.org.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.thriplow.org.uk$
RewriteRule ^cms/category/([0-9]+)/(.+).pc index.php?mact=News,cntnt01,default,0&cntnt01detailpage=59&cntnt01category_id=$1&cntnt01returnid=59 [NC,L]
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# except for form POSTS
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 ^(.+).pc$ index.php?page=$1 [QSA]
Let me know if this doesn't make the magic happen, and I'll setup a test server on my local machine to mirror your directory and URL hierarchy and get it worked out.
Re: Pretty URL's for News Category Browse Links?
Posted: Fri Aug 05, 2011 4:40 pm
by swarfega
Thanks very much owens, categories work nicely now.
Re: Pretty URL's for News Category Browse Links?
Posted: Fri Aug 05, 2011 5:03 pm
by Owens
Thank you for saying thank you. Glad I could help.

Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 5:20 pm
by ladyr0gue
Hi - I'm sorry too for jumping on an old thread... I just wondered if there's any way I could write
Code: Select all
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^news/category/([0-9]+)/(.+).htm index.php?mact=News,cntnt01,default,0&cntnt01detailpage=15&cntnt01category_id=$1&cntnt01returnid=15 [NC,L]
to test on my local server?
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 6:29 pm
by Owens
ladyr0gue wrote:I just wondered if there's any way I could write ... to test on my local server?
Open your CMS Made Simple config.php file on your local server and look for the line that has
$config['root_url'] = to figure out what you should replace yoursite.com in the above code with.
This will vary depending upon your what you are using as your local server. I use Server2Go on my Windows machines. So in the .htacess file I would replace yoursite.com with 127\.0\.0\.1:4001
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 6:46 pm
by ladyr0gue
Owens wrote:ladyr0gue wrote:I just wondered if there's any way I could write ... to test on my local server?
Open your CMS Made Simple config.php file on your local server and look for the line that has
$config['root_url'] = to figure out what you should replace yoursite.com in the above code with.
This will vary depending upon your what you are using as your local server. I use Server2Go on my Windows machines. So in the .htacess file I would replace yoursite.com with 127\.0\.0\.1:4001
thanks for your reply

as my root url is
http://localhost/cmsms how would I write that? just localhost/cmsms? or do i use a backslash? thanks x
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 6:49 pm
by Dr.CSS
I've found that using XAMPP I had to use...
RewriteBase /cmsms
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 7:51 pm
by ladyr0gue
Dr.CSS wrote:I've found that using XAMPP I had to use...
RewriteBase /cmsms
Thanks for your reply - I am still doing something wrong boohoo!
here's what I have.
UDT news_category_url
Code: Select all
$name = preg_replace(array("/ /", "/[^A-Za-z0-9-\-]/", "/--/"),array("-", "", "-"),$params['name']);
$id = $params['id'];
echo 'blog/category/'.$id.'/'.$name.'.html';
News category browse default template
Code: Select all
{if $count > 0}
<ul class="list1">
{foreach from=$cats item=node}
{if $node.depth > $node.prevdepth}
{repeat string="<ul>" times=$node.depth-$node.prevdepth}
{elseif $node.depth < $node.prevdepth}
{repeat string="</li></ul>" times=$node.prevdepth-$node.depth}
</li>
{elseif $node.index > 0}</li>
{/if}
<li class="newscategory">
{if $node.count > 0}
<a href="{news_category_url name=$node.news_category_name id=$node.news_category_id}">{$node.news_category_name}</a> ({$node.count}){else}<span>{$node.news_category_name} (0)</span>{/if}
{/foreach}
{repeat string="</li></ul>" times=$node.depth-1}</li>
</ul>
{/if}
.htaccess file
Code: Select all
Options -Indexes
Options +FollowSymLinks
DirectoryIndex /cmsms/index.php
RewriteBase /cmsms
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^news/category/([0-9]+)/(.+).html
index.php?mact=News,cntnt01,default,0&cntnt01detailpage=3&cntnt01category_id=$1&cntnt01returnid=3 [NC,L]
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L,NE]
# 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,NE]
and no change. I've done something wrong!
*I do wonder if I've set myself up for complications in that I have the installation in a folder named cmsms in xampp/htdocs rather than unpacked straight into the htdocs folder...
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 8:00 pm
by Dr.CSS
I wouldn't use the root of htdocs folder, as it has a lot of things in it needed for XAMPP and your CMSMS may get lost amongst them...
I wonder if you need to move the News part of the htaccess below the others...
Re: Pretty URL's for News Category Browse Links?
Posted: Thu Apr 19, 2012 8:18 pm
by ladyr0gue
I tried, no difference unfortunately. Is my code otherwise correct? I don't have a folder named news but all my pretty urls for the other parts of the site seem to work fine including detail view for news articles, I get something like
"
http://localhost/cmsms/news/2/66/My-Pretty-Page.html
I have also tried this different solution here
http://wiki.cmsmadesimple.org/index.php ... stallationbut seemed to come up with more problems - but I notice that the RewriteBase wasn't set for /cmsms when I tried that one.
I also tried using
Code: Select all
RewriteCond %{HTTP_HOST} ^localhost/cmsms$
but no difference, I wonder if I wrote it right?
(btw thanks for the confirmation, glad I am ok to have it in the folder as I don't think my poor lil brain could handle it if it had to be moved! lol)