Rewrite custom urls with Joomla SEF

1.5k views Asked by At

I'm trying to wrap my head around rewriting some urls internally in Joomla! 1.7 with SEF features turned on but can't seem to figure it out:

The following SEF URL exists (menu item):

website.com/local/amsterdam

What I would like is the following:

http://website.com/local/amsterdam/trends (non-existant) to render http://website.com/local/amsterdam?show=trends while still displaying the first URL.

Working with .htaccess the following works (but doesn't show SEF URL):

RewriteRule ^local/amsterdam/trends$ index.php?option=com_content&view=article&id=14&Itemid=176&show=trends [L]

But this doesn't:

RewriteRule ^local/amsterdam/trends$ local/amsterdam?show=trends [L]

I'm hoping to find a solution without having to use an id so that it will dynamically render the correct page for all cities. I'ld appreciate any thoughts on doing this in .htaccess as well as any different solutions to achieve this! Thanks in advance.

1

There are 1 answers

0
jessedb On BEST ANSWER

Although I was initially searching for a mod-rewrite solution I have figured out a way to achieve the same by modifying the (core) Joomla! router.

On line 47 of includes/router.php after:

$path = substr_replace($path, '', 0, strlen(JURI::base(true)));

I added the following:

$subpages = array("trends","other"); //Add URL segments you want to reroute
foreach ($subpages as $subpage):            
     if (strstr($path, "/".$subpage)) :
          $path = str_replace("/".$subpage, "", $path);
          $vars['show'] = $subpage;
     endif;
endforeach;

Now when loading http://www.website.com/local/amsterdam/trends, this URL is displayed while the page http://www.website.com/local/amsterdam is actually loaded with the ?show=trends parameter.

For me this a more flexible solution than using mod-rewrite even though a core file is modified. You might want to use some conditional statements to only run this code in certain conditions. Hope it helps.