AllowOverride
设置为All
且mod_write
已加载并正常工作(例如,如果我在.htaccess
中输入一些随机数据,则会收到500错误),但是它没有进行重写,因此,我得到了404.为什么?
htaccess的
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule api/(.*)$ api/api.php?id=$1 [QSA,NC,L]
</IfModule>
树
/srv/www/htdocs/
├── api
│ ├── api.php
│ ├── .htaccess
│ └── index.php
目录conf
<Directory "/srv/www/htdocs">
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
Options None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride All
# Controls who can get stuff from this server.
<IfModule !mod_access_compat.c>
Require all granted
</IfModule>
<IfModule mod_access_compat.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
示例网址:http://localhost/api/11122233A
没有error_log
答案 0 :(得分:2)
由于.htaccess
位于api
目录中,请使用:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) api.php?id=$1 [QSA,L]
</IfModule>