htaccess 配置

问题描述 投票:0回答:1

我正在 apache 服务器和 php 上测试一些东西。在我的项目的根源,我有这个 htaccess 配置文件

RewriteEngine On
RewriteBase /react/

# API requests
RewriteCond %{REQUEST_URI} ^/react/api/
RewriteRule ^api/(.*)$ routes/api.php?controller=$1 [QSA,L]

# Non-API requests
RewriteCond %{REQUEST_URI} !^/react/api/
RewriteRule ^(.+)$ routes/web.php?controller=$1 [QSA,L]

我想将以“api”开头的请求重定向到“api.php”,将其他请求重定向到“web.php”。但是,在当前配置下,所有请求都将重定向到“web.php”。我无法确定问题所在。请帮助我。

(抱歉,如果我的文字中有任何错误;我的英语不流利。)”

(抱歉,如果我的文字中有一些错误,我的英语不流利)

我尝试了很多事情,例如我做了这个

RewriteEngine On
RewriteBase /react/

# API requests
RewriteCond %{REQUEST_URI} ^/react/api/
RewriteRule ^api/(.*)$ routes/api.php?controller=$1 [QSA,L]

# Non-API requests
RewriteCond %{REQUEST_URI} !^/react/api/
RewriteRule ^([^/]+)$ routes/web.php?controller=$1 [QSA,L]

这有效,但是当我有这种 url 'localhost/react/client/something' 时它不起作用

php regex apache .htaccess
1个回答
0
投票

我知道,我必须修改我的正则表达式

我做到了并且有效

    RewriteEngine On
RewriteBase /react/

# API requests
RewriteRule ^api/(.*)$ routes/api.php?controller=$1 [QSA,L]

# Non-API requests
RewriteRule ^(?!.*api).*$ routes/web.php [QSA,L]

© www.soinside.com 2019 - 2024. All rights reserved.