Results 1 to 3 of 3
  1. #1

    php + mod_rewrite + friendly urls

    Hey guys, I need some help with mod_rewrite. I'm completely clueless how to set this up.

    I know it has to go in .htaccess, but thats about it.

    I have URLs like the following:
    index.php?id=page page is page.php

    And I would like them to be domain.com/id/page

    I use this for the id=blah bit:

    Code:
     <?PHP 
    $id = $_GET['id']; if (!isset($id)) { $id = 'home'; } 
    if (strstr($id,'/')) { $id = 'no'; } 
    if (!file_exists($id . '.php')) { 
    echo('404 <b>' . $id . '.php</b> could not be found!'); 
    } 
    else { 
    include($id . '.php'); 
    } 
    ?>
    Would greatly appreciate it if someone could help me.
    Thanks.

  2. #2
    Note: I tried editing but it didn't work.

    I was looking around and found this, which according to the example works how I want it to.

    Code:
    
    RewriteEngine on
    RewriteRule ^id/([^/\.]+)/?$ index.php?id=$1 [L]
    It *does* work, the only thing is it completely ignores my css. So My guess is its actually redirecting to the page, instead of including it. So how would I make it include it, so it works normally?

  3. #3
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    mod_rewrite doesn't do includes -- just redirections based on URLs.

    Suggest you do some troubleshooting in your index.php file.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

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