Why RewriteRule isn't working on my wamp?
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/c开发者_运维问答ategory/([0-9]+)/?$ /category.php?category_id=$1 [NC,L]
I put the file in:
localhost/.htaccess"category.php" page is in:
localhost/website/category.phpI tried:
localhost/website/category/4/But it said:
The requested URL /website/public/category/5/ was not found on this server.
BTW, I tested .htaccess with another simpler rule and it was working.
First of all:
When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done.
So in case of the document root directory, remove the leading /
from the pattern:
RewriteRule ^category/([0-9]+)/?$ /category.php?question_id=$1 [NC,L]
Secondly, since your base path is actually /website/
and not /
, change the base path with RewriteBase
:
RewriteBase /website/
Note that this base path applies to all rules in this .htaccess file. So you rather might want to change just the particular rules, for example:
RewriteRule ^website/category/([0-9]+)/?$ /website/category.php?question_id=$1 [NC,L]
精彩评论