views:

90

answers:

2

I'm trying to get Apache mod rewrite to work on my local machine. I'm running OSX with PHP 5 and the Apache mod rewrite module is enabled.

I have a directory called localhost/~Jason/hfh/admin with various PHP includes called based on a $_GET variable. I want to let users type (in theory)

localhost/~Jason/hfh/admin/pages

and have that URL stay in the address bar, while what gets displayed is

localhost/~Jason/hfh/admin/?admin=pages

So.

I've created a .htaccess file that sits in the /hfh directory. Inside, I've put this mod rewrite text:

RewriteEngine On
RewriteRule ^admin/([^/.]+)/?$ admin/?admin=$1 [L]

When I go to the browser and type

localhost/~Jason/hfh/admin/pages

I get a "Problem loading page" error, and Firefox says, "Oops. Firefox can't load this page for some reason."

Can anyone help me figure this out? I have such a hard time with regex and mod rewrite...

A: 

Try explicitly writing index.php in your RewriteRule.

RewriteRule ^admin/([^/.]+)/?$ admin/index.php?admin=$1 [L]

You may also find it to be cleaner organization to just move this directive to a .htaccess file in /admin/ itself, thus removing duplication in the rule and making the rule easier to find later.

Matchu
I added the index.php (though you shouldn't have to, right?) and still no change. I'll gladly move the rule down into /admin/ if it ever works, but I'd like to get it working first!
Jason Rhodes
try adding RewriteBase
yoda
I've had the RewriteBase in there at times, it makes no difference. I had: RewriteBase localhost/~Jason/hfh/
Jason Rhodes
@Jason Rhodes: The base would be just `/~Jason/hfh/`.
Gumbo
Thanks. That base didn't make it work, though. Still at a total loss.
Jason Rhodes
A: 

So far the answer appears to be: you can't use mod-rewrite on localhost.

Jason Rhodes