Skip to main content

Redirecting URLS on Apache with mod_rewrite

By April 12, 2013September 12th, 2022No Comments

In this tutorial we are working on openSUSE 11.4, but generally, this is consistent across distributions. We look at redirecting URLS received on our Apache web server. This may be because files have changes their names or locations, or simply redirecting HTTP to HTTPS connections. Mod_rewrite is very powerful and we show you the basics and how to get started.

First we have make sure the the module is loaded. In SUSE this is maintained by /etc/sysconfig/apache2 and we make sure that mod_rewrite is listed within the APACHE_MODULES section. Other distros will require you to add a LoadModule directive to the httpd.conf. We can then restart the serevr and using the command:

apache2ctl -M

We can list the loaded modules and check that mod_ rewrite shows.

Now we can start to rewrite our URLS in the video we wish to relocate a web page, in the simplest format we can add this to out httpd.conf:

RewriteEngine On
RewriteBase /
RewriteRule ^old.html sales.html

This would rewrite a URL that starts with old.html to sales.html