簡體   English   中英

Apahce / .htaccess-將所有請求重定向到單個頁面,但該頁面使用的資產除外

[英]Apahce/.htaccess - Redirect all requests to a single page except assets used by that page

在LAMP堆棧環境中工作,我遇到以下問題。

我想對Apache發出所有請求以返回特定頁面(即,所有> request將返回fixing.php)。 但是fix.php本身要求幾個資產>(圖像,css文件)正確顯示。

例:

從Apache的角度來看,用戶請求: apple.html

使用.htaccess redirectMatch的Apache返回 fixing.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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM