PDA

Click to See Complete Forum and Search --> : mod_rewrite help - matching .php extension


ppeter
Aug 4th, 2004, 10:11 AM
Hi Guys,

I have the following in my .htaccess:

RewriteEngine on
RewriteRule ^/?$ template.php?section=home&page=home [L]
RewriteRule ^index.php?$ template.php?section=home&page=home [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ template.php?section=$1&page=$2 [L]

The first two RewriteRules work fine, but the last one... current will match something like ..com/section/page/ whereas I want it to match ..com/section/page.php

I've tried fiddling with it, but no luck. I'm very new to mod_rewrite.

Thanks, Phil

ppeter
Aug 4th, 2004, 10:21 AM
UPDATE:
I got the mod-rewrite to work (sort of)

RewriteEngine on
RewriteRule ^/?$ template.php?section=home&page=home [L]
RewriteRule ^index.php?$ template.php?section=home&page=home [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/.php?$ template.php?section=$1&page=$2 [L]

Except it doesn't give me that page... i just gives back

<html><body></body></html>

Any ideas?

techgnome
Aug 4th, 2004, 12:04 PM
I'm new to this mod_rewrite thing, as cool as it is, but
Try echoing the value of $page from inside template.php, make sure that it's comming in right.

Secondly, I think that when it's encountering the / it is outside the parens, soooo.... maybe it should be:

RewriteRule ^([^/\.]+)/([^/\.]+.php)?$ template.php?section=$1&page=$2 [L]

But I'm not sure.

TG

ppeter
Aug 5th, 2004, 03:43 AM
Almost... just needed to escape the '.' on the '.php' and it worked..

RewriteRule ^([^/\.]+)/([^/\.]+\.php)?$ template.php?section=$1&page=$2 [L]

Only thing is, $2 now includes the .php extension. I'll just have to snip it out with some PHP.

Thanks for your help :bigyello: