使用 REST api 为 html5mode 编写 .htaccess 文件
Writing a .htaccess file for html5mode with a REST api
我正在尝试让 html5mode 工作,通过将其添加到我的 .htaccess 文件中,我能够使其工作。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
我有一个名为 api.php 的 php 文件,与我的 index.html 文件位于同一文件夹中,该文件将处理后端 REST api。
基本上我希望 html5mode 继续工作,但所有请求例如 localhost/api/ ... 都将发送到 api.php
我尝试了几行,但它破坏了 html5 模式。
如果我能弄清楚这个就太棒了。
此致
此配置是在另一个答案中建议的。
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api.php
# otherwise forward it to index.html
RewriteRule ^.*$ - [NC,L]
RewriteRule ^. /index.html [NC,L]
我正在尝试让 html5mode 工作,通过将其添加到我的 .htaccess 文件中,我能够使其工作。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
我有一个名为 api.php 的 php 文件,与我的 index.html 文件位于同一文件夹中,该文件将处理后端 REST api。
基本上我希望 html5mode 继续工作,但所有请求例如 localhost/api/ ... 都将发送到 api.php
我尝试了几行,但它破坏了 html5 模式。
如果我能弄清楚这个就太棒了。
此致
此配置是在另一个答案中建议的。
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !/api.php
# otherwise forward it to index.html
RewriteRule ^.*$ - [NC,L]
RewriteRule ^. /index.html [NC,L]