【问题标题】:RewriteRule base and specific pathRewriteRule 基础和特定路径
【发布时间】:2013-11-14 00:02:22
【问题描述】:

我基本上已经为自己开发了一个自定义框架,它使用以下 .htaccess 行从 index.php 运行所有内容

RewriteRule .* index.php [QSA,L]

我现在已经开发了一个 REST API,我需要通过相同的服务器/根目录运行,我尝试将以下 URL 添加到 .htaccess 中,只是提示使用自定义 404 我已集成到我的自定义框架,所以基本上它忽略了这一行,只是尝试将 RewriteRule 用于我的自定义框架

RewriteRule /api/v1/(.*)$ myAPI.php?request=$1 [QSA,NC,L]

我怎样才能得到它,这样我的 API url 就不会作为查询传递给我的其他 RewriteRule

我的 .htaccess 如下所示

Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10

AddType "text/html; charset=UTF-8" html 
AddType "text/plain; charset=UTF-8" txt

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # if file not exists
    RewriteCond %{REQUEST_FILENAME} !-f

    # if dir not exists
    RewriteCond %{REQUEST_FILENAME} !-d

    # avoid 404s of missing assets in our script
    RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC]

    # rest api url
    RewriteRule ^api/v1/(.*)$ /myAPI.php?request=$1 [QSA,NC,L]

    # core framework url rewriting
    RewriteRule .* index.php [QSA,L]
</IfModule>

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    从规则中删除前导斜杠:

    RewriteRule ^api/v1/(.*)$ /myAPI.php?request=$1 [QSA,NC,L]
    

    .htaccess 是每个目录指令,Apache 从 RewriteRule URI 模式中去除当前目录路径。

    【讨论】:

    • 它仍然忽略了 RewriteRule,我已将我的 .htaccess 添加到问题中
    • 您可以尝试将文件存在和目录存在行注释掉并重新测试吗?
    • 我注释掉无济于事
    • 您在/api//api/v1/ 中是否有任何.htaccess
    • /api//api/v1/ 不是有效目录,它们仅用于 RewriteRule
    猜你喜欢
    • 2014-03-03
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2016-12-20
    • 2014-12-28
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多