.htaccess-重写特定文件夹的通配符
我想重定向任何来自以下网站的内容:.htaccess-重写特定文件夹的通配符,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我想重定向任何来自以下网站的内容: http://example.com/api/ /* e.g. http://example.com/api/anything */ 致: 以下是我正在尝试但失败的内容: RewriteEngine On RewriteRule ^api/ http://localhost:3002/api/ [R=301,L] 我知道我可以单独做路线 Redirect 301 /api/thisaddress http://localhost:3002/api/thi
http://example.com/api/ /* e.g. http://example.com/api/anything */
致:
以下是我正在尝试但失败的内容:
RewriteEngine On
RewriteRule ^api/ http://localhost:3002/api/ [R=301,L]
我知道我可以单独做路线
Redirect 301 /api/thisaddress http://localhost:3002/api/thisaddress
但我宁愿有一个通配符。。。有办法做到这一点吗
更新
由于该网页是一个单页应用程序,我目前在.htaccess
文件中已经有:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]
您可以使用:
RewriteEngine On
RewriteRule ^api/ http://localhost:3002%{REQUEST_URI} [NE,NC,R=301,L]
%{REQUEST_URI}
表示以/api/…
开头的原始URI
或者,您也可以使用:
RewriteRule ^api/.*$ http://localhost:3002/$0 [NE,NC,R=301,L]
R=301
和L
标志一起没有真正意义,是吗?事实上,我在一个测试用例中注意到,即使使用R=3xx
,仍然需要L
。我将尝试重现这个问题。我不适合我,我已经更新了我认为可能是important@DarrenSweeney:将此规则放在RewriteEngine
行下方,并确保完全清除浏览器缓存。这听起来像是您在努力使其简单化,而使其复杂化。您是否试图在同一目录和同一虚拟主机上运行两个不同的应用程序(前端和后端)?@Hayden否,同一服务器上有多个节点站点,因此存在端口问题
RewriteRule ^api/.*$ http://localhost:3002/$0 [NE,NC,R=301,L]