#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    110
    Rep Power
    24

    Multiple folders and multiple options


    I've checked out the mod rewrite sticky, but it doesn't cover what I'd like to do and I can't seem to modify it in anyway.

    Here's what I'd like to do, but I'm stuck at just the first one. I can get that one, but not the following one in conjunction with the first. Seems to be one or the other.

    foo.com/blah
    foo.com/index.php?cat=blah

    foo.com/read/info_here
    foo.com/read.php?item=XX

    I'd also like to learn how to add more to it if possible.

    Here's what I have now...
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ index.php?cat=$1 [L]
    Last edited by mbreezy; June 7th, 2012 at 01:00 PM.
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    What did you have that tried to use both? Note that you do need two expressions: one because the URL is /foo->index and another because the URL is /foo/bar->foo.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    110
    Rep Power
    24
    I used this line in there as well...
    Code:
    RewriteRule ^read/(.*)$ read.php?item=$1 [L]
  6. #4
  7. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    The other expression
    Code:
    ^(.+)$
    will match "read/info_here" too.

    Put this new rule before the other. Specific rules first, generic "catch-all" rules later. Or you can modify the first expression so that it's less powerful, like only matches paths that don't include slashes:
    Code:
    ^([^/]+)$
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    110
    Rep Power
    24
    Thanks man!

    However, now my CSS isn't showing up. Could it be that because my CSS uses an external file it's reading that incorrectly?

    Here's what I got now...

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^read/(.+)$ rule.php?item=$1 [L]
    RewriteRule ^(.+)$ index.php?cat=$1 [L]
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    110
    Rep Power
    24
    Okay, I've been working on this for days and I'm starting to think what I want is just impossible...

    All I want is
    foo.com/blah = foo.com/index.php?id=blah

    AND
    foo.com/read/blah = foo.com/read.php?id=blah

    I've searched everywhere, tried probably 50 different things and nothing. It has to be something else. Could it be because I'm currently using a sub folder to execute all of this on? Currently I'm testing this out on foo.com/folder so in reality it would be foo.com/folder/read/blah or foo.com/folder/blah

    I'm at a loss. I can get the foo.com/folder/blah to work, but other than that, no idea.

    Also, do I even need the rewritecond's in there?
  12. #7
  13. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    No you don't need them, but it's a good idea. Should have them on both rules even.

    So the CSS and such is the problem now, right? The actual rewriting is working? You need to change your links to be absolute rather than relative.
    Code:
    <link rel="stylesheet" type="text/css" href="css/foo.css" />
    If you use that in read.php then the browser will look for "/read/css/foo.css" because it thinks /read/ is the current directory. If you use an absolute URL like
    Code:
    <link rel="stylesheet" type="text/css" href="/css/foo.css" />
    then the browser will always look for "/css/foo.css" regardless of the directory.

IMN logo majestic logo threadwatch logo seochat tools logo