简单的重写示例,mod_rewrite 404问题

时间:2015-11-28 15:17:47

标签: apache .htaccess mod-rewrite

AllowOverride设置为Allmod_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

1 个答案:

答案 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>