apache redirect from non www to www

Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution: <VirtualHost *:80> ServerName example.com Redirect permanent / http://www.example.com/ </VirtualHost> <VirtualHost *:80> ServerName www.example.com # real server configuration </VirtualHost> And then you’ll have another <VirtualHost> section with ServerName www.example.com for your real server configuration. Apache automatically preserves anything … Read more

How to debug Apache mod_rewrite

One trick is to turn on the rewrite log. To turn it on, try this line in your Apache HTTP Server main configuration or current virtual host file (not in .htaccess): LogLevel alert rewrite:trace6 Before Apache httpd 2.4 mod_rewrite, such a per-module logging configuration did not exist yet. Instead you could use the following logging … Read more

How to enable mod_rewrite for Apache 2.2

In order to use mod_rewrite you can type the following command in the terminal: sudo a2enmod rewrite Restart apache2 after sudo /etc/init.d/apache2 restart or sudo service apache2 restart or as per new unified System Control Way sudo systemctl restart apache2 Then, if you’d like, you can use the following .htaccess file. <IfModule mod_rewrite.c> RewriteEngine On … Read more