Results 1 to 15 of 15

Thread: Help me write mod rewrite code

  1. #1
    Banned
    Join Date
    Aug 2004
    Posts
    132

    Smile How to write mod rewrite code for multiple directories

    I'm using the following code to rewrite my urls and thankfully it's working:
    RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)
    RewriteRule ^(.*) /index.php?menu=%1&cat=%2&artist=%3&title=%4 [L]
    but I want it to work for every directory. I tried the following but it doesn't seem to work:
    RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)
    RewriteRule ^(.*) /index.php?menu=%1&cat=%2&artist=%3 [L]
    RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)
    RewriteRule ^(.*) /index.php?menu=%1&cat=%2 [L]
    RewriteCond %{REQUEST_URI} ^/([^/]+)
    RewriteRule ^(.*) /index.php?menu=%1 [L]


    Can anybody help?
    Last edited by lz83ny; 04-16-2005 at 07:50 PM. Reason: Nintendo gave me the solution

  2. #2
    Banned
    Join Date
    Aug 2004
    Posts
    132
    This is a url:
    http://www.google.com/music-vid...American-Idiot/ that works with my current mod rewrite, however http://www.google.com/music-videos/Rock-Music/ doesn't, so I want my mod rewrite to work for every virtual directory, such as:

    http://www.google.com/music-videos/
    http://www.google.com/music-videos/Rock-Music/
    http://www.google.com/music-vid...usic/Green-Day/

    I hope it clarifies what my intentions are.
    Last edited by lz83ny; 11-25-2005 at 10:23 PM.

  3. #3
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    Code:
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ index.php?menu=$1&cat=$2&artist=$3&title=$4 [L]
    RewriteRule ^(.*)/(.*)/(.*)/$ index.php?menu=$1&cat=$2&artist=$3 [L]
    RewriteRule ^(.*)/(.*)/$ index.php?menu=$1&cat=$2 [L]
    RewriteRule ^(.*)/$ index.php?menu=$1 [L]

  4. #4
    Banned
    Join Date
    Aug 2004
    Posts
    132
    OMG, I've been told at sitepoint that it's impossible to do it, but I guess nothing is impossible for you, Nintendo. You saved me days, or maybe even weeks of wasting my time trying to find the solution. You're a legend!
    Last edited by lz83ny; 04-16-2005 at 07:45 PM.

  5. #5
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166
    Mod_rewrite is COOL!!!!! Once you figure it out then you NEVER want to have those ugly .php/.cgi URLs again!!!!! And of course at the same time, Google suddenly loves the site!

    The first two Options lines might not be needed, that depends on the server.

    Quote Originally Posted by Dean C
    It's impossible to write a rule to encompass every single possible amount of sub-virtual directories. You'll need to match everything after your domain including a /. Then use your script to take the URL you have and manipulate it to get the relevant content. Unfortunately this is out of the scope of the Apache forum I think
    Dude! You sure you know what you are talking about!!

  6. #6
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    They're full of **** if they said something like that couldn't be done, because it is done--and very frequently.

  7. #7
    Registered Member moonshield's Avatar
    Join Date
    Aug 2004
    Location
    Charlotte
    Posts
    1,281
    i dont really understand all these ** stars. What do they mean?

  8. #8
    Banned
    Join Date
    Aug 2004
    Posts
    132
    **** stand for "fill in the blanks"

  9. #9
    Registered Member moonshield's Avatar
    Join Date
    Aug 2004
    Location
    Charlotte
    Posts
    1,281
    that makes good sense indeed.

  10. #10
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    sh¡t (man I'm tricky)

  11. #11
    Registered Member moonshield's Avatar
    Join Date
    Aug 2004
    Location
    Charlotte
    Posts
    1,281
    . What did you say!

    Nintendo's example does help me out a bunch. Thanks dude.

  12. #12
    Registered ordinary_guy's Avatar
    Join Date
    Feb 2005
    Posts
    28
    He's really helpful and polite.
    Shopping Sites:1 2

  13. #13
    King of da Wackos Nintendo's Avatar
    Join Date
    Oct 2004
    Location
    Planet Zeekois
    Posts
    166

    Talking

    Quote Originally Posted by ordinary_guy
    He's really helpful and polite.
    ME???!!! I don't know about that!!! I annoy some people, especially when it has to do with AWS!!

  14. #14
    Web Monkey MarkB's Avatar
    Join Date
    Nov 2003
    Location
    London, UK
    Posts
    1,783
    Haha!!!!!
    Stepping On Wires - the new blog

  15. #15
    I'm the oogie boogie man! James's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,566
    j00 Ennoy peeple?!111111111111111 :PL0000000L!11111!!!!!! HAHA!!





    :P

Similar Threads

  1. Html code help needed
    By loveinstar in forum HTML, CSS, Layout, and Design
    Replies: 2
    Last Post: 04-12-2005, 08:00 PM
  2. Mod Rewrite, to Remove Spaces
    By Emancipator in forum Website Programming & Databases
    Replies: 2
    Last Post: 11-06-2004, 05:02 PM
  3. Is there something wrong with my google code?
    By Sootah in forum Advertising & Affiliate Programs
    Replies: 6
    Last Post: 11-05-2004, 10:27 AM
  4. I need to write an article
    By Chris in forum Site and Forum Feedback
    Replies: 19
    Last Post: 06-08-2004, 02:51 PM
  5. Interesting Website Code I Found
    By grichards in forum Search Engine Optimization
    Replies: 2
    Last Post: 12-10-2003, 09:02 AM

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
  •