mdance
mdance

Reputation: 996

Getting 404 with mod_rewrite

I am trying to use mod_rewrite to clean up some dynamic URLS that I have.

My .htaccess in the root of the site is as follows:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^equipment/AlarisSystem/([^/]*)/([^/]*)$ /equipment/AlarisSystem/?manu=$1&model=$2 [L]

I want to rewrite from http://www.mysite.com/equipment/AlarisSystem/?manu=test1&model=test2 to http://www.mysite.com/equipment/AlarisSystem/test1/test2

If I were to type in the above "clean" address i get a 404 error. I have done research, and cannot find where I am going wrong. And yes, mod_rewrite is enabled. Thanks for your help.

EDIT I know that my .htaccess file is being read. I did this to check:

Redirect /google.html http://www.google.com and this rule works correctly.

Upvotes: 0

Views: 535

Answers (1)

mpontes
mpontes

Reputation: 3004

Your rule seems correct, but you're probably not rewriting into the right place. Where's the script you want to rewrite into? It seems you're rewriting into a directory.

Perhaps you have additional rewriting rules that need to be applied further, in that case, you should get rid of the last rule [L] flag. Having it there makes mod_rewrite stop applying rules.

If you want to check whether your query is being caught or not, you can set RewriteLog and RewriteLogLevel directives to help you.

For a quick check, you can also set the [R] flag, and then you'll be able to see in your browser where mod_rewrite is sending you to.

Update: Your original rule works for me with an index.php file in the directory, even, but perhaps you can try using a RewriteBase to solve this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /equipment/AlarisSystem/
RewriteRule /([^/]*)/([^/]*)$ index.php?manu=$1&model=$2 [L]

I see no reason for that rule to not work. The original error you're getting is probably related to where you're doing your rewriting. This is from an .htaccess file in the root.

Upvotes: 1

Related Questions