简体   繁体   中英

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

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 (ie all >request will return fixing.php). However fixing.php itself requests a couple of assets >(images, css files) to appear correctly.

Example:

From Apache's point of view, the user requests: apple.html

Apache using .htaccess redirectMatch returns fixing.php

As fixing.php renders on the browser, the browser request two assets style.css and background.jpg. However Apache recieves these reqeuest and still just returns fixing.php (hence you get a loop).

How does one configure an .htaccess file do this?

I've tried :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /fixed.php [L,R=301]

On the basis that the only files that existed were the fixed.php, and the style.css file - by my logic - if the requested file is not a file (ie doesn't exist) or a directory that's reqeusted isn't there - return fixed.php

You can use:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_REFERER} !fixed\.php
RewriteRule ^ /fixed.php [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM