HowTo: Apache2 permanent redirect from path to URL

HowTo

Configure a permanent redirect from a defined path to another URL.

Step by step instruction

  1. Login as root user to the UCS system via SSH
  2. Change the template file /etc/univention/templates/files/etc/apache2/ucs-sites.conf.d/ucs-sites.conf

These two lines should be added and the content is similiar like this:
The path and the URL must be changed to the fitting values in your scenario.

##Change for redirecting the path "/path" to "https://redirected.url.net"
Redirect 301 /path https://redirected.url.net

Template file looks then like:

@%@UCRWARNING=# @%@

RewriteEngine on
RewriteOptions Inherit
ProxyPreserveHost on
ProxyTimeout 600

RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
RequestHeader set "X-Forwarded-SSL" expr=%{HTTPS}

DocumentRoot @%@apache2/documentroot@%@
CustomLog /var/log/apache2/access.log combined

##Change for redirecting the path "/path" to "https://redirected.url.net"
Redirect 301 /path https://redirected.url.net

@!@
print('RedirectMatch ^/$ /%s' % configRegistry.get('apache2/startsite', 'univention/'))
@!@

The path and the URL must be changed to the fitting values in your scenario.

  1. Commit the changes to the active used configuration from Apache with ucr commit /etc/apache2/ucs-sites.conf.d/ucs-sites.conf
  2. Reload the Apache configuration with systemctl reload apache2.service
  3. Test the changes
2 Likes

This topic was automatically closed after 24 hours. New replies are no longer allowed.

Mastodon