apache mod_rewrite displays object not found 404

2019-07-15 07:42发布

问题:

I have a link http://localhost/css/dictionary?letter=a which I want to make it like this http://localhost/css/dictionary/a

but somehow it says 404 message

Am i missing something here? this is my code in .htaccess please help me.

RewriteEngine On
RewriteBase /css/


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^\.]+)$ $1.php [NC]


RewriteRule ^([a-zA-Z])$ dictionary?letter=$1

I've been scouring all the youtube videos and reading articles and so far im still in trouble please i need your help.

回答1:

It's because you have 2 rules, and the first one matches first (as it is more general than the second).

The second doesn't even check for dictionary at all.

The second condition should be:

RewriteRule ^dictionary/([a-zA-Z])$ dictionary.php?letter=$1