rhodesjason
rhodesjason

Reputation: 5014

Why won't this mod-rewrite rule work?

I have a development site on my machine at

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

My .htaccess file is in the /hfh/admin/ directory. It says:

RewriteEngine On
RewriteBase /~Jason/hfh/
RewriteRule ^([A-Za-z0-9\-\_]*)$ index.php?admin=$1

But when I go to

localhost/~Jason/hfh/admin/collections

I get a "page not found" error. Can anyone tell me why?

(This is related to another question at this link.)

Upvotes: 0

Views: 228

Answers (3)

rhodesjason
rhodesjason

Reputation: 5014

The short, direct answer for now appears to be: you can't use mod_rewrite on your localhost.

Upvotes: 0

Simeon Pilgrim
Simeon Pilgrim

Reputation: 25903

If you have the .htaccess file in /hfh/admin/ make that the base to begin with.

RewriteBase /~Jason/hfh/admin/

then you may see what you expect. Also you'll may want a clause to not redirect when the File/Directory exists.

Does typing the expected result URL work?

/~Jason/hfh/admin/index.php?admin=Collections

Edit:

So what happens if you change the whole lot to:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~Jason/hfh/admin/index.php?admin=$1 [L]

Upvotes: 1

Jeffrey Aylesworth
Jeffrey Aylesworth

Reputation: 8470

It looks like that would be sending you to the page /~Jason/hfh/index.php?admin=collections, when you want /~Jason/hfh/admin/index.php?admin=collections.

Try changing the rule to:

RewriteRule ^([A-Za-z0-9\-\_]*)$ admin/index.php?admin=$1

Upvotes: 0

Related Questions