Skip to content

Instantly share code, notes, and snippets.

@julian-klode
Last active March 22, 2017 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julian-klode/600237d0b61cf92b01748b25cf5921d7 to your computer and use it in GitHub Desktop.
Save julian-klode/600237d0b61cf92b01748b25cf5921d7 to your computer and use it in GitHub Desktop.
changelog components redirector .htaccess file
# Boilerplate
Options +Indexes
RewriteEngine on
## Sample redirect rules for every section.
#
# This file assumes that the changelogs are exposed at /changelogs/pool/COMPONENT/..., like
# on the Debian and Ubuntu servers, and that changelogs is a subdirectory of the document root.
#
# The first condition prevents infinite redirects (alternative: RewriteCond $1 !^main$)
# The second condition checks if the requested document exists in another component
# The redirect rule finally performs the redirect to the other commponent
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{DOCUMENT_ROOT}/changelogs/pool/main/$2" -f
RewriteRule "pool/(.*?)/(.*)" "/changelogs/pool/main/$2" [R=301,L]
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{DOCUMENT_ROOT}/changelogs/pool/restricted/$2" -f
RewriteRule "pool/(.*?)/(.*)" "/changelogs/pool/restricted/$2" [R=301,L]
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{DOCUMENT_ROOT}/changelogs/pool/universe/$2" -f
RewriteRule "pool/(.*?)/(.*)" "/changelogs/pool/universe/$2" [R=301,L]
RewriteCond "%{REQUEST_FILENAME}" !-f
RewriteCond "%{DOCUMENT_ROOT}/changelogs/pool/multiverse/$2" -f
RewriteRule "pool/(.*?)/(.*)" "/changelogs/pool/multiverse/$2" [R=301,L]
@julian-klode
Copy link
Author

julian-klode commented Mar 15, 2017

You might want to handle ? parameters in the RewriteRule by adding (\?.*)? to the source and $3 to the target, so these are preserved.

Oh, it actually seems to just work, even without special handling :)

@nacc
Copy link

nacc commented Mar 22, 2017

Thanks Julian. This was deployed today on changelogs.ubuntu.com!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment