Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
Hello,
I'm rewriting a page called team.php that takes the $_GET variable of teamid.
Right now the URL rewriting makes this URL look like this "http://www.bball.tf/team/?teamid=9"
where I want the URL to look like this, "http://www.bball.tf/team/9"
The rewrite rule looks like this,

#team.php
RewriteRule ^team$ "$0/" [R=301,L,QSA]
RewriteRule ^team/$ team.php [L,QSA]
RewriteRule ^team/.*?([^\.\/]*)\.html$ team.php?pname=$1 [L,QSA]
RewriteRule ^team/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ team.php?d=$1$2$3 [L,QSA]
RewriteRule ^team/[^\.]*?([^/\.]*)/$ team.php?fname=$1 [L,QSA]
RewriteRule ^team/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

Any help would be appreciated.
Thanks.
Hi :)

To do that you'll have to use 'custom routes' - please see
viewtopic.php?f=5&t=8981
http://www.couchcms.com/docs/custom-routes/

That said, the default URLs created by Couch would result in your page looking like -
http://www.bball.tf/team/some-team.html
I.e., instead of the 'id', it will show the team name in the URL.
If that could do, you might find it much easier to stick to the default prettyURls.

Hope this helps.
:D Hey
The problem with this is it uses the Couch templates and I want my approach to be purely done with PHP and .htaccess.
The page does not include any Couch content with the exception of the footer but I used the htaccess gen to create the file. This doesn't seem to allow me rewrite the url how I want, so that the page is /team/teamid.
However, I cannot get a rewrite rule that does this to work, I had tried to use this
Code: Select all
RewriteRule ^team.php?params=$1 [NC]

but it just redirected to my index, presumably due to the rest of the htaccess which I don't entirely understand.

Cheers,
Seth
Seth, I'll presume team.php *is* a Couch managed template (i.e. it has <?php require_once("couch/cms.php"); ?> and <?php COUCH::invoke(); ?> in it). Right?

If that is so, then Couch will impose upon it a set of rewrite rules that are specific to it. Overriding the rules in .htaccess won't work as the CMS will try to redirect the pages to the URL it understands.

By using 'custom routes', however, you can ask it to skip applying these default rules and then you can define your own.

I am sorry, if you have included Couch in your template then it cannot be a "purely done with PHP and .htaccess" approach as Couch's own code would be executing on every run of that template and you'll have to contend with it.

Hope I was able to explain myself.
Hey, thanks for your response.
My understanding of the custom routing however is that it works only for the specific couch views?
I am not using a couch view for this page, the variable I am trying to rewrite is used outside of the CMS.

I want to still be able to do this
Code: Select all
$_GET['teamid']

but also still have couch on the page to do this
Code: Select all
<cms:embed 'sidebar.php' />


Is it possible to transform my /team.php?teamid=1 to /team/1 ?
Currently using the pretty URLS rewrites it only to /team/?teamid=1

Sorry if I've misunderstood.
Cheers.
See, what we can do is make Couch move out of the way and let you decide what kind of rewrite rules you want to apply.

For that, use the following as the closing statement of team.php template -
Code: Select all
<?php COUCH::invoke( K_IGNORE_CONTEXT ); ?>

With the code above in place, Couch will no longer apply any of its default rules to the template.

So now you can edit the .htaccess file, delete the Couch generated rules for the template and put in your own rules.

Would this help?
6 posts Page 1 of 1
cron