PDA

View Full Version : Help me write mod rewrite code



lz83ny
04-16-2005, 11:23 AM
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?

lz83ny
04-16-2005, 04:39 PM
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.

Nintendo
04-16-2005, 05:16 PM
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]

lz83ny
04-16-2005, 07:39 PM
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!

Nintendo
04-16-2005, 10:33 PM
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! :D

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


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!! :D:D:D:D

James
04-16-2005, 11:22 PM
They're full of **** if they said something like that couldn't be done, because it is done--and very frequently.

moonshield
04-17-2005, 07:23 AM
i dont really understand all these ** stars. What do they mean? :D

lz83ny
04-17-2005, 08:15 AM
**** stand for "fill in the blanks"

moonshield
04-17-2005, 08:21 AM
that makes good sense indeed.

James
04-17-2005, 03:54 PM
sh¡t (man I'm tricky)

moonshield
04-17-2005, 06:44 PM
:o. What did you say!

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

ordinary_guy
04-21-2005, 01:47 AM
He's really helpful and polite.

Nintendo
04-22-2005, 12:16 AM
He's really helpful and polite.

ME???!!! I don't know about that!!! :D:D:D:D I annoy some people, especially when it has to do with AWS!! :D

MarkB
04-22-2005, 12:49 AM
Haha!!!!! :D:D

James
04-22-2005, 07:49 AM
j00 Ennoy peeple?!111111111111111 :PL0000000L!11111!!!!!! HAHA!! :D:D:D:D:D:D:D:D:D:D





:P