Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2003
    Posts
    657

    mod_rewrite question..

    Hi,
    I have been looking around at google and I just can't seem to be able to find the code for the mod_rewrite for the following issue:
    I have php files structured like this:
    page.php?id=3

    What I want to do is to use mod_rewrite to make the pages look like this:
    page3.html

    Is this possible?

    Also, will it rewrite the pages fully, so I can even link to the files in this format: page3.html
    And also, will what will it show in the status bar of the link when linking, because right now my links are in the format of: page.php?id=3

    Thanks alot

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Yes this is possible.

    Your links will be to page3.html

    This rule *should* work, but its not 100% (untested):
    Code:
    RewriteEngine on
    RewriteRule page(.*).html page.php?id=$1
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  3. #3
    Join Date
    May 2003
    Posts
    598
    If you find the code above does not work, add this line to the top
    Code:
    Options +FollowSymLinks
    It's a common fix for most server problems people have using mod_rewrite.

  4. #4
    Join Date
    Apr 2004
    Location
    East Anglia, UK
    Posts
    79
    RewriteEngine on
    RewriteRule page(.*).html page.php?id=$1
    Ouch, Pure evil.... this would make:
    page3-blah-blah-blah.html
    turn into:
    page.php?id=3-blah-blah-blah

    which i'm sure you don't want.

    A slightly better idea would be the following.

    Code:
    RewriteEngine on
    RewriteBase /dir/containing/page
    RewriteRule page([0-9]+).html page.php?id=$1 [PT]
    This limits the part on the end of page#.html to a sequence of numbers.

    RewriteBase is relative to the sites document root. [PT] just means passthrough, which means the end user doesn't get a "Page Temporarily Moved" header.

    If you only want a single digit at the end of page, remove the + from the rule.

    Regards,

    Leigh.

  5. #5
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Good catch Leigh
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  6. #6
    Join Date
    Dec 2003
    Posts
    657
    its not working, here is what my entire htaccess file looks like:
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /absolute/path
    RewriteRule page([0-9]+).html page.php?id=$1 [PT]
    I did change the absolute path and its 100% correct, I know for a fact

  7. #7
    Join Date
    Dec 2003
    Posts
    657
    anyone?

  8. #8
    Join Date
    Apr 2004
    Location
    East Anglia, UK
    Posts
    79
    noo, not an absolute path, relative to the document root

    so if page.php is http://www.domain.com/something/pages/page3.html

    you should have
    RewriteBase /something/pages

    might have to allow override of FileInfo too, not sure though.

Posting Permissions

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