在LAMP堆栈环境中工作,我遇到以下问题。
我想对Apache发出所有请求以返回特定页面(即,所有> request都将返回fixing.php)。但是fix.php本身要求几个资产>(图像,css文件)正确显示。
例:
从Apache的角度来看,用户要求:
apple.html
Apache使用.htaccess redirectMatch返回
fix.php
在fixing.php在浏览器上呈现时,浏览器请求两个资源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]