logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Global ads.txt for all sites on server
Author
csdude55



Joined: 22 Jan 2023
Posts: 23
Location: USA, Wilkesboro

PostPosted: Tue 09 Jul '24 18:49    Post subject: Global ads.txt for all sites on server Reply with quote

I have over 100 sites on my VPS. Most of them use the same info for ads.txt, but that data changes about once a month and it's a HUGE pain to manually update all of the sites!

So I'd like to rewrite example.com/ads.txt to a global ads.txt file. Via Apache .CONF files, of course, so that I could do it once and it would apply to all future sites unless I manually exclude them.

I thought that this would work, allowing me to upload to /home/ads.txt (not web accessible), set the permission to 0777, and all of the sites would use it:

Code:
RewriteEngine on
RewriteRule /ads\.txt /home/ads.txt



But alas, no, it's not working. When I go to foo.com/ads.txt, it shows the original file instead of the data from /home/ads.txt.

Variations that I tried, but none of them did anything:

Code:
# with and without opening /
RewriteRule /ads\.txt /home/ads.txt
RewriteRule ads\.txt /home/ads.txt

# without escaped .
RewriteRule /ads.txt /home/ads.txt
RewriteRule ads.txt /home/ads.txt

# Thinking maybe I can't rewrite pre-directory, so
# upload it to example.com
RewriteCond %{HTTP_HOST} !example\.com [NC]
RewriteRule /ads.txt https://www.example.com/ads.txt [R=301,L]

RewriteCond %{HTTP_HOST} !example\.com [NC]
RewriteRule ads.txt https://www.example.com/ads.txt [R=301,L]



Any suggestions on what I'm doing wrong?

I know that I could symlink all of them to the one file, but then I'd have to remember to do it each time I add a new site! So I'd consider that a last resort if I can't get the rewrite to work.
Back to top
tangent
Moderator


Joined: 16 Aug 2020
Posts: 342
Location: UK

PostPosted: Tue 09 Jul '24 20:33    Post subject: Reply with quote

Unless I'm missing something, can't you simply use an alias directive in your configuration to reference your global file, e.g.
Code:
Alias "/ads.txt" "/home/ads/ads.txt"

<Directory "/home/ads">
    Require all granted
</Directory>

Note, assuming the target directory is outside the DocumentRoot, you'll need to explicitly grant access to the target directory.

Since this file changes, you might want to consider adding a cache-control/max-age response header to this file request.
Back to top
csdude55



Joined: 22 Jan 2023
Posts: 23
Location: USA, Wilkesboro

PostPosted: Wed 10 Jul '24 7:39    Post subject: Reply with quote

Awesome, using "Alias" worked out great Smile Honestly, I code in the configuration so rarely that I forgot that Alias existed! LOL
Back to top


Reply to topic   Topic: Global ads.txt for all sites on server View previous topic :: View next topic
Post new topic   Forum Index -> Apache