Question

So, I'm using Concrete5 as CMS, and I'm trying to rewrite an already rewriten url.

So, I've this url http://url.com/index.php?cID=144&id=4, which rewrites to http://url.com/rengas?id=1.

But, I want to rewrite it to http://url.com/rengas/1 , and so far I've been unable to do that.

So here's my htaccess:

# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --

RewriteEngine On
RewriteRule ^rengas/([^/]*)$ /index.php?cID=144&id=$1 [L]

As you can probably quess, I generated the rule using http://www.generateit.net/mod-rewrite/index.php which does a pretty good job, but this time it has failed me.

Was it helpful?

Solution

let's say your single page is called testpage.php and is located at root/single_pages/testpage.php

By creating a controller, you can capture the data after the last slash
for example: mysite.com/testpage/123

your controller file is located at: root/controllers/testpage.php

the content of your controller (to adapt it to your code, do not forget to adjust the name of the class, in your example that would be ...rengasController extends...) ==

<?php  
defined('C5_EXECUTE') or die("Access Denied.");
class testpageController extends Controller {
    public function view($id){
    //here you can do anything with the captured id. 
// here you can set the id to give it to your single page using following code:
$this->set('id', $id);
// the code above will make a variable $id to use in the code of the single page
            }
        }
?>

I know the explanation above might be a bit hard to understand, so here are some links to understand the MVC (single-pages and controller) system in Concrete5 a bit better:

http://www.concrete5.org/documentation/recorded-trainings/single-pages/basic-application-development-part-one/ (see Creating a single page controller and view)
http://www.concrete5.org/documentation/how-tos/developers/basic-mvc-in-concrete5/ (see single page controller)

and here's an example i wrote (available for about 14 days) : http://ge.tt/api/1/files/9eheDrP1/0/blob?download

If the file above is not available or if you are reluctant to download, here's a pastie of the code : http://pastie.org/8906708

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top