SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru marcel's Avatar
    Join Date
    Nov 2000
    Posts
    920
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple mod rewrite to pass through index.php

    How do I force every single request to pass through index.php ?
    Except .css, .js , gif, jpg, png, swf

    This only works on .php files

    RewriteRule ^(.*)\.php$ /site/index.php?id=$1

    Many Grateful Thanks in advance...

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    marcel,

    Your regex should cause a loop, not just redirect your support files through index.php!

    Okay, I'm a believer in being as specific as you can when dealing with regex (there are exceptions) so I'd recommend taking the EVERYTHING atom out and constraining your PAGE names to lowercase with php, htm and html as possible extensions. That said, it's easy enough to just pass the root directory's filename (w/o extension) as the query string value:
    Code:
    RewriteEngine On
    RewriteRule ^([a-z]+)\.(php|htm|html)$ site/index.php?id=$1 [L]
    This regex demands one or more lower case letters in the filename of a php, htm or html script and redirects to the site/index.php script with query string consisting of the original filename. If you need that extension, too, move the first atom's ) to just in front of the $. Remember that regex will only work on "filenames" in the current (root) directory.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

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