Working in LAMP stack environment, I have the following issue.
I would like to have all request made to Apache to return a specific page (i.e. all >request will return fixing.php). However fixing.php itself requests a couple of assets >(images, css files) to appear correctly.
示例:
从 Apache 的 Angular 来看,用户请求: apple.html
Apache 使用 .htaccess redirectMatch 返回 fixing.php
当 fixing.php 在浏览器上呈现时,浏览器请求两个 Assets style.css 和 background.jpg。然而,Apache 收到这些请求,仍然只返回 fixing.php(因此你得到一个循环)。
如何配置 .htaccess 文件来做到这一点?
我试过了:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /fixed.php [L,R=301]
基于唯一存在的文件是 fixed.php 和 style.css 文件 - 按照我的逻辑 - 如果请求的文件不是文件(即不存在)或请求的目录不是在那里 - 返回 fixed.php
最佳答案
您可以使用:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_REFERER} !fixed\.php
RewriteRule ^ /fixed.php [L,R=301]
关于php - Apache/.htaccess - 将所有请求重定向到单个页面,但该页面使用的 Assets 除外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22204724/