mod_rewrite
May 11, 2005 3:12 PM   Subscribe

I've been trying to get a mod rewrite thingie to work for the past day, and I'm tired of bashing my head against my desk.

I need to turn:
http://domain.com/~karl/foo
into
http://domain.com/~karl/page.php?pageid=foo

Unfortunately, when I use this:

RewriteEngine on
RewriteBase /~karl/
RewriteRule (.*) page.php?pageid=$1 [L]

it somehow sets $1 as page.php, when it should be $foo

I'm confused. I know I suck with regexp, but I can't seem to figure out a rule that'll do what I want.
posted by SpecialK to Computers & Internet (5 answers total)
 
It's probably rewriting the request for ~karl/page.php too, you have to make that page exempt from the rewrite rule. I'm not sure how to do capturing and negative-matching at the same time though, if it turns out that the above was the problem and you can't figure it out (mod_rewrite is damn complicated) post a followup and I'll give the documentation a shot.
posted by fvw at 3:30 PM on May 11, 2005


Best answer: This CSS cheat sheet might be able to help. I recently used mod_rewrite to point root requests to my blog. A simple redirect wouldn't do due to security that's in place. I think you need [ L(ast rule),, R(edirect)] in the end bit.

RewriteEngine on
RewriteBase /~karl/
RewriteRule (.*) page.php?pageid=$1 [L,R]
posted by mnology at 4:17 PM on May 11, 2005


Err..not CSS..mod_rewrite. I'm in a different place now.
posted by mnology at 4:20 PM on May 11, 2005


Response by poster: Redirecting here isn't going to be the answer, unfortunately. The reason I'm doing this is for a CMS that has everyting as http://site.com/page.php?pageid=[pagename], but the customer wants to be able to type http://site.com/pagename and not have to see the querystring.
posted by SpecialK at 4:32 PM on May 11, 2005


Response by poster: Aah! But the mod_rewrite cheat sheet had the solution.

RewriteRule ^([A-Za-z0-9-]+)/?$ page.php?pageid=$1 [L]
posted by SpecialK at 4:36 PM on May 11, 2005


« Older Livejournal and DNS   |   Just as long as it's not "Chalk & Awe" Newer »
This thread is closed to new comments.