Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite Fustrations

Status
Not open for further replies.

darwin2kx

Technical User
Sep 28, 2006
3
CA
Hello
I am working on a mod_rewrite rule to lay out new URLs for my site.

Some example URLs for pages:
/media.php
/media.php?p=users
/news.php
/news.php?p=archives
/news.php?p=archives&d=2007-02
/docs.php
/docs.php?p=about

And I want to have the URLs like this:
/media
/media/users
/news
/news/archives
/news/archives/2007-02
/docs
/docs/about

I know that I could have a separate rule for every page on the site, but I want to have one rule that will do the translation to $p=, then just have another rule for pages that need more URL params, like news.

I tried:
Code:
RewriteRule ^/(.*)/(.*)$ /$1.php?p=$2

However, this rule only works for URLs like
/media
/news
etc

When I try /media/users for ex, it doesn't load proper, and in the log it shows that it translated to /media.php/users
I don't have enough experience with regex and I can't seem to find the documentation that would help me figure this out. Does anyone have a rule that would work for that catch-all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top