【问题标题】:Redirect all requests to index.html EXCEPT requests to the /api folder将所有请求重定向到 index.html,但对 /api 文件夹的请求除外
【发布时间】:2017-05-29 01:58:29
【问题描述】:

我需要让 Apache 将所有请求汇集到 index.html 文件(不包括资源请求 - js、css 等),但是任何进入 /api 文件夹的请求都需要汇集到 Laravel 前端控制器:/api/public /index.php

谁能与我分享他们的 .htaccess 知识以帮助完成此任务?

【问题讨论】:

标签: php regex apache laravel


【解决方案1】:

好的,得到我的答案。这是怎么做的:

1 - 将任何请求发送到 /api 文件夹到 Laravel 前端控制器。

2 - 将除此之外的任何其他文件发送到 index.html 文件。

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/api/
RewriteRule (.*) /api/public/index.php [L]

RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

【讨论】:

  • 谢谢,对我来说很好用。使用 PHP API 实现一个 React 应用程序。
猜你喜欢
  • 2013-02-15
  • 2012-12-07
  • 2015-05-30
  • 1970-01-01
  • 2015-03-21
  • 1970-01-01
  • 2013-10-26
  • 1970-01-01
  • 2016-05-04
相关资源
最近更新 更多