Pretty URL's for News Category Browse Links?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
The Peckham Plater
New Member
New Member
Posts: 2
Joined: Mon Jan 26, 2009 11:30 pm

Pretty URL's for News Category Browse Links?

Post 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.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: Pretty URL's for News Category Browse Links?

Post 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).
Last edited by Owens on Sat Aug 06, 2011 11:39 pm, edited 5 times in total.
swarfega
Forum Members
Forum Members
Posts: 174
Joined: Mon Sep 06, 2010 10:51 am

Re: Pretty URL's for News Category Browse Links?

Post 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.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: Pretty URL's for News Category Browse Links?

Post 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):
swarfega
Forum Members
Forum Members
Posts: 174
Joined: Mon Sep 06, 2010 10:51 am

Re: Pretty URL's for News Category Browse Links?

Post 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]
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: Pretty URL's for News Category Browse Links?

Post 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.
swarfega
Forum Members
Forum Members
Posts: 174
Joined: Mon Sep 06, 2010 10:51 am

Re: Pretty URL's for News Category Browse Links?

Post by swarfega »

Thanks very much owens, categories work nicely now.
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: Pretty URL's for News Category Browse Links?

Post by Owens »

Thank you for saying thank you. Glad I could help.
:)
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Pretty URL's for News Category Browse Links?

Post 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?
User avatar
Owens
Forum Members
Forum Members
Posts: 97
Joined: Thu Dec 27, 2007 11:29 pm

Re: Pretty URL's for News Category Browse Links?

Post 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
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Pretty URL's for News Category Browse Links?

Post 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
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Pretty URL's for News Category Browse Links?

Post by Dr.CSS »

I've found that using XAMPP I had to use...

RewriteBase /cmsms
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Pretty URL's for News Category Browse Links?

Post 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...
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Pretty URL's for News Category Browse Links?

Post 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...
ladyr0gue
Forum Members
Forum Members
Posts: 91
Joined: Fri Feb 17, 2012 4:25 pm

Re: Pretty URL's for News Category Browse Links?

Post 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)
Post Reply

Return to “Modules/Add-Ons”