1

我基本上为自己开发了一个自定义框架,它使用以下 .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>
4

1 回答 1

1

从规则中删除前导斜杠:

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

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

于 2013-11-03T04:44:04.113 回答