Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Using <Location> but excluding some sites / pages |
|
Author |
|
csdude55
Joined: 22 Jan 2023 Posts: 23 Location: USA, Wilkesboro
|
Posted: Fri 22 Dec '23 7:32 Post subject: Using <Location> but excluding some sites / pages |
|
|
I'm playing around with mod_substitute. This is my sandbox script:
Code: | <Location "/">
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<body.*?>)|<script>var foo = 1, bar = 14;</script><script src="//example.com/lorem.js"></script>\n$1|iq"
</Location> |
Or possibly reversing that and placing $1 before <script>. Either way, my plan is to place this in the /etc/apache2/conf.d/userdata directory, so that it applies to all of the sites on the server.
Now I have 2 modifications that I'd like to consider:
1. Let's say that I want to explicitly exclude certain websites. This would be easier than manually including sites, since I expect 190 out of 200 of them to use this. What is the best way to exclude them from the substitution, other than manually typing 190 of them into an <If> (and then modifying it every time I add a site)? Is it possible to enter a TXT record to their DNS, and then have Apache read that TXT record?
2. Let's say that I have a website that I want to use the substitution, but I have certain pages in that site that I want to exclude. The URLs are auto-generated, so there's nothing in the address that I could use to automatically know that it should be excluded; eg,
https://www.example.com/c/?id=1234
If it helps, the pages are written in PHP and select from MySQL, and if the results of that query contain certain predefined words or phrases then they plug in a custom header:
header('X-Foo: true');
But it's my understanding that <Location> runs before that, so I don't think that would be helpful.
Any other suggestions on how I might exclude those pages from the substitution?
TIA! |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7374 Location: Germany, Next to Hamburg
|
|
Back to top |
|
|
|
|
|
|