Skip to content Skip to navigation

Force Proxied Sites to Load via the Vanity URL

Author: 

If you have a website at https://ponies.stanford.edu that is pointing to a Drupal install at https://www.stanford.edu/group/ponies/cgi-bin/drupal, and you want to force loading through the Vanity URL only (and avoid the broken CSS and links kerfuffle), you will need to modify the .htaccess file at the root of your drupal install, and add the following code right after the line that starts with RewriteBase.

Use This Code If Your Proxy Is on the Proxy Servers

(How do I tell where my proxy is located?)

# Force loading through the vanity URL
RewriteCond %{HTTP:X-Forwarded-Host} !^ponies.stanford.edu*
RewriteCond %{REQUEST_URI} !webauth
# Uncomment the following line if you have any WebAuthed file directories
# RewriteCond %{REQUEST_URI} !files\/secure
RewriteRule (.*) https://ponies.stanford.edu/$1 [R=301,L,QSA]

Use This Code If Your Proxy Is on the WWW Servers

(How do I tell where my proxy is located?)

# Force loading through the vanity URL
RewriteCond %{HTTP_HOST} !^ponies.stanford.edu*
RewriteCond %{REQUEST_URI} !webauth
# Uncomment the following line if you have any WebAuthed file directories
# RewriteCond %{REQUEST_URI} !files\/secure
RewriteRule (.*) https://ponies.stanford.edu/$1 [R=301,L,QSA]

As noted above, if you are using WebAuth to protect any file directories (e.g., via a .htaccess file in that directory, as detailed here), you will need to uncomment and edit the # RewriteCond %{REQUEST_URI} !files\/secure line to match the path to your WebAuthed file directory. If you don't, the browser will go into an infinite loop, and hilarity will ensue.

This trick should work on any proxied site, not just Drupal.

As usual, thanks to Marco for supplying us with this code!