我正在 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' 时它不起作用
我知道,我必须修改我的正则表达式
我做到了并且有效
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]