Results 1 to 4 of 4

Thread: mod_rewrite help - matching .php extension

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    21

    mod_rewrite help - matching .php extension

    Hi Guys,

    I have the following in my .htaccess:

    Code:
    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
    I am Remus, come from the dead

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    21
    UPDATE:
    I got the mod-rewrite to work (sort of)

    Code:
    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

    Code:
    <html><body></body></html>
    Any ideas?
    I am Remus, come from the dead

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    21
    Almost... just needed to escape the '.' on the '.php' and it worked..

    Code:
    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
    I am Remus, come from the dead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width