This tutorial will cover the steps for configuring mod_rewrite on your Kyup container.


Mod_rewrite is an Apache module which uses a rule-based rewriting engine based on regular-expressions to rewrite the requested URL on the fly. It is really flexible and powerful for URL manipulation. For example, if you have URL and would like the output to be transformed to, you need to use a mod_rewrite rule.

Installation Guides

- On CentOS:

Before we begin with the mod_rewrite setup, Apache web server needs to be installed on your Kyup container. To install Apache you have to run:

and then to start it using:

Mod_rewrite in included by default in Apache, so we just need to activate it. Open the configuration file /etc/httpd/conf/httpd.conf with your favorite text editor and change:


(normally you should find this around line 338). Save and close the config. After that you need to restart the service to apply all changes using:

- On Ubuntu/Debian:

First, we need to update the container repositories list using the following command:

Then you need to install Apache web server if you have not installed it yet:

The configuration file of the Apache web server is here: /etc/apache2/apache2.conf. The mod_rewrite module is installed by default, but in order to active it you have run the command below:

and then to restart the web service:

If mod_rewrite has been successfully loaded on your Kyup container, you should have this file:


with the following content:

To allow .htaccess files to override the predefined website configs we need to open for editing /etc/apache2/sites-available/default.

You need to navigate your cursor to the directive for your website and make the following changes:


The default configuration should look as follows:

After that change Apache needs to be restarted.

For details related to the Apache AllowOverride directive, you can refer to the official documentation.


1) Redirect visitors of your website to access the site WITH “www” prefix

Please create or open, if exists, the .htaccess file in DocumentRoot directory of your website and add the following lines replacing the variables with appropriate values where necessary:

2) Redirect visitors of your website to access the site WITHOUT "www" prefix

Create or open .htaccess file in the documentroot directory and add: