My way of changing news pretty url's
Posted: Thu Aug 21, 2008 2:16 pm
Hey guys, as some may have already noticed, I have found a workaround for the news module pretty url's.
Please keep in mind that this is just my personal solution, and may interfere with other modules/options of the news module, and changing files is fully on your own risk (therefore, ALWAYS BACKUP YOUR FILES, unlike I did...
).
Just an example of what we are trying to reach:
(I hate all the capitals in an url, so I'm going for lowercased url's)
You start with: http://www.domain.com/News/1/12/Your-Article-Title-Here
But we are creating: http://www.domain.com/yournewstitle/1/1 ... title-here
--
Okay, here we go, a couple of simple steps will do the trick.
1. Open file News.module.php
Find this lines (around ~line 68 on the unpatched 2.8 module):
(Remember, "yournewstitle", the bold part, can be ANYTHING, it's just an example)
Find these lines (around ~line 355 on an unpatched 2.8 module):
(Again remember, "yournewstitle", the bold part, can be ANYTHING, it's just an example)
Okay, so now we're actually done, but there's more (wow, I just sound like a tellsell narrator
), we can add the news date into the url, looks like and comes in handy every now and then I think.
Optional 3. Still in file action.default.php:
Above the following lines (you just added):
http://www.domain.com/yournewstitle/11/ ... icle-title
Enjoy, use it as you want, I just thought I'd share it.
Please keep in mind that this is just my personal solution, and may interfere with other modules/options of the news module, and changing files is fully on your own risk (therefore, ALWAYS BACKUP YOUR FILES, unlike I did...

Just an example of what we are trying to reach:
(I hate all the capitals in an url, so I'm going for lowercased url's)
You start with: http://www.domain.com/News/1/12/Your-Article-Title-Here
But we are creating: http://www.domain.com/yournewstitle/1/1 ... title-here
--
Okay, here we go, a couple of simple steps will do the trick.
1. Open file News.module.php
Find this lines (around ~line 68 on the unpatched 2.8 module):
Then replace them with something like these:$this->RestrictUnknownParams();
$this->RegisterRoute('/[nN]ews\/(?P[0-9]+)\/(?P[0-9]+)\/(?P.*?)\/d,(?P.*?)$/');
$this->RegisterRoute('/[nN]ews\/(?P[0-9]+)\/(?P[0-9]+)\/(?P.*?)$/');
$this->RegisterRoute('/[nN]ews\/(?P[0-9]+)\/(?P[0-9]+)$/');
$this->RegisterRoute('/[nN]ews\/(?P[0-9]+)$/');
$this->RegisterRoute('/[nN]ews\/(?Prss)\/(?P.*?)$/', array('showtemplate'=>'false'));
$this->RegisterRoute('/[nN]ews\/(?Prss)$/', array('showtemplate'=>'false'));
(Remember, "yournewstitle", the bold part, can be ANYTHING, it's just an example)
2. Open up file action.default.php$this->RestrictUnknownParams();
$this->RegisterRoute('/[yY]ournewstitle\/(?P[0-9]+)\/(?P[0-9]+)\/(?P.*?)\/d,(?P.*?)$/');
$this->RegisterRoute('/[yY]ournewstitle\/(?P[0-9]+)\/(?P[0-9]+)\/(?P.*?)$/');
$this->RegisterRoute('/[yY]ournewstitle\/(?P[0-9]+)\/(?P[0-9]+)$/');
$this->RegisterRoute('/[yY]ournewstitle\/(?P[0-9]+)$/');
$this->RegisterRoute('/[yY]ournewstitle\/(?Prss)\/(?P.*?)$/', array('showtemplate'=>'false'));
$this->RegisterRoute('/[yY]ournewstitle\/(?Prss)$/', array('showtemplate'=>'false'));
Find these lines (around ~line 355 on an unpatched 2.8 module):
Then, replace them with something like these:$aliased_title = munge_string_to_url($row['news_title']);
$prettyurl = 'news/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title";
(Again remember, "yournewstitle", the bold part, can be ANYTHING, it's just an example)
--$aliased_title = munge_string_to_url($row['news_title']);
$aliased_title_stripped = preg_replace("/[^a-z0-9-]/i", "", $aliased_title);
$aliased_title_lowercase = strtolower($aliased_title_stripped);
$prettyurl = 'yournewstitle/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title_lowercase";
Okay, so now we're actually done, but there's more (wow, I just sound like a tellsell narrator

Optional 3. Still in file action.default.php:
Above the following lines (you just added):
Add the following:$aliased_title = munge_string_to_url($row['news_title']);
$aliased_title_stripped = preg_replace("/[^a-z0-9-]/i", "", $aliased_title);
$aliased_title_lowercase = strtolower($aliased_title_stripped);
$prettyurl = 'yournewstitle/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title_lowercase";
Then, change your pretty url (see below):$news_date = date('d-m-Y', strtotime($row['news_date']));
To something like:$prettyurl = 'yournewstitle/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$aliased_title_lowercase";
This way, you will get the following url:$prettyurl = 'actueel/'.$row['news_id'].'/'.($detailpage!=''?$detailpage:$returnid)."/$news_date/$aliased_title_lowercase";
http://www.domain.com/yournewstitle/11/ ... icle-title
Enjoy, use it as you want, I just thought I'd share it.
