php - Apache/.htaccess - 将所有请求重定向到单个页面,但该页面使用的 Assets 除外

标签 php css apache .htaccess mod-rewrite

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/

相关文章:

php - 将 php sql 结果从垂直转换为水平

php - 从表名中获取实体类名

php - 根据单元格中的多个值选择表格

javascript - 哪个是适合开发以 php 作为后端的单页应用程序的 javascript 框架?

html - 在图像的底部开始内容容器

html - 表格中的图像对齐问题

apache - 无法为 Apache 反向代理后面的 Bonita soft 指定 URL

html - 纯 CSS : unlimited nesting accordion?

azure - 如何调试 Apache 中损坏的响应 header ?

php - 使用 IIS 实现搜索引擎友好的 URL