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.
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.
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
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
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
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
RewriteRule ^([A-Za-z0-9-]+)/?$ page.php?pageid=$1 [L]
posted by SpecialK at 4:36 PM on May 11, 2005
This thread is closed to new comments.
posted by fvw at 3:30 PM on May 11, 2005