By default, Ubuntu 13.04 doesn’t enable the rewrite engine module after installing Apache. The rewrite engine for Apache allows for on-the-fly URL rewriting/changing. This allows for the use of urls that are human readable, and SEO friendly. The rewrite engine is capable of capturing a website request, running it through a series of expression checks, and if a match is found, it will pass on the rewritten request to the web server. The end user would not notice anything different within their web browser, other than perhaps easier to read urls. The rewrite engine is great for re-directions, and is a requirement for some CMS packages such as Drupal.
This guide assumes that Apache is already installed on your machine. If it not installed, please install it first using the command “sudo apt-get install apache2”
Follow the steps below to enable the rewrite engine.
Enable the rewrite module using the command “sudo a2enmod rewrite”
Depending on which website you want the rewrite engine to work on, you may need to modify the Apache configuration files some more.
For the default website, open up the “/etc/apache2/sites-available/default” file in your favorite editor. I am using “nano” for this example
The file should look something like the image below. The lines you will need to focus on are the ones that start with “AllowOverride”.
You need to change the “AllowOverride None” to be “AllowOverride All” for the directories you want the rewrite engine to work in. There are other options that can be used for the AllowOverride feature, but I won’t be going into the details of those in this article.
Exit the editor, and Save the file.
Restart Apache using “sudo /etc/init.d/apache2 restart”
If Apache hasn’t been configured for a ServerName option yet, you may get the above error message, or something similar. This isn’t a huge concern, and can be resolved later.
You should now be able to create .htaccess files, and use them how you want.
By default, Ubuntu 12.04 doesn’t enable the rewrite engine module after installing Apache. The rewrite engine for Apache allows for on-the-fly URL rewriting/changing. This allows for the use of urls that are human readable, and SEO friendly. The rewrite engine is capable of capturing a website request, running it through a series of expression checks, and if a match is found, it will pass on the rewritten request to the web server. The end user would not notice anything different within their web browser, other than perhaps easier to read urls. The rewrite engine is great for re-directions, and is a requirement for some CMS packages such as Drupal.
This guide assumes that Apache is already installed on your machine. If it not installed, please install it first using the command “sudo apt-get install apache2”
Follow the steps below to enable the rewrite engine.
Enable the rewrite module using the command “sudo a2enmod rewrite”
Depending on which website you want the rewrite engine to work on, you may need to modify the Apache configuration files some more.
For the default website, open up the “/etc/apache2/sites-available/default” file in your favorite editor. I am using “nano” for this example
The file should look something like the image below. The lines you will need to focus on are the ones that start with “AllowOverride”.
You need to change the “AllowOverride None” to be “AllowOverride All” for the directories you want the rewrite engine to work in. There are other options that can be used for the AllowOverride feature, but I won’t be going into the details of those in this article.
Exit the editor, and Save the file.
Restart Apache using “sudo /etc/init.d/apache2 restart”
If Apache hasn’t been configured for a ServerName option yet, you may get the above error message, or something similar. This isn’t a huge concern, and can be resolved later.
You should now be able to create .htaccess files, and use them how you want.
If you have a web server running nginx that accepts both http and https connections, there may be times where you want to prevent anyone from accessing a specific page/url using a insecure http connection. For example, login or registration pages. You always want these to be secure if you can.
Add the following into the main “location /” block, located in the http “server” section in your nginx configuration file for your site.
if ($request_uri ~* "/login.php") { rewrite ^ https://$host$request_uri permanent; }
Note: This assumes your HTTP and HTTPS “server” sections/site details seperated in the nginx site configuration file, otherwise it would end up in a loop.
eg:
#HTTP Site Details server { listen 80; <...config details removed...> location / { <...config details removed...> if ($request_uri ~* "/login.php") { rewrite ^ https://$host$request_uri permanent; } } } #HTTPS Site details server { listen 443; ssl on; <...config details removed...> location / { <...config details removed...> } }
It also assumes your HTTPS connection is using the default https port (port 443). You can change the url to go to a different port using “https://$host:port$request_uri permanent;” and replace port with the port number you are using for https connections.
Restart nginx, and test.
When you go to http://your.web.site/login.php in your web browser, it should now redirect you to https://your.web.server/login.php automatically.
By default, Ubuntu 10.04 doesn’t enable the rewrite engine module after installing Apache. The rewrite engine for Apache allows for on-the-fly URL rewriting/changing. This allows for the use of urls that are human readable, and SEO friendly. The rewrite engine is capable of capturing a website request, running it through a series of expression checks, and if a match is found, it will pass on the rewritten request to the web server. The end user would not notice anything different within their web browser, other than perhaps easier to read urls. The rewrite engine is great for re-directions, and is a requirement for some CMS packages such as Drupal.
This guide assumes that Apache is already installed on your machine. If it not installed, please install it first using the command “sudo apt-get install apache2”
Follow the steps below to enable the rewrite engine.
Enable the rewrite module using the command “sudo a2enmod rewrite”
Depending on which website you want the rewrite engine to work on, you may need to modify the Apache configuration files some more.
For the default website, open up the “/etc/apache2/sites-avaliable/default” file in your favorite editor. I am using “nano” for this example
The file should look something like the image below. The lines you will need to focus on are the ones that start with “AllowOverride”.
You need to change the “AllowOverride None” to be “AllowOverride All” for the directories you want the rewrite engine to work in. There are other options that can be used for the AllowOverride feature, but I won’t be going into the details of those in this article.
Exit the editor, and Save the file.
Restart Apache using “sudo /etc/init.d/apache2 restart”
If Apache hasn’t been configured for a ServerName option yet, you may get the above error message, or something similar. This isn’t a huge concern, and can be resolved later.
You should now be able to create .htaccess files, and use them how you want.