Question
How to check if mod_rewrite
is enabled on customer's website?
Answer
Check the following module on the corresponding Web Server in the list of Apache modules:
# httpd -M | grep rewrite Syntax OK rewrite_module (shared)
Check that this module is enabled via phpinfo page for this domain. Create
phpinfo.php
file with the following content in the root directory of the webste:<?php phpinfo(); ?>
Access
http://example.com/phpinfo.php
and make sure that MOD_REWRITE module is shown as 'enabled'.Modify
.htaccess
file to enable mod_rewrite for a single website:<IfModule mod_rewrite.c> #check if mod rewrite is enabled SetEnv MOD_REWRITE enabled RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
The above
.htaccess
file (if placed in the DocumentRoot) will redirect all traffic to the index.php file of the website root directory.Create the following files to test mod_rewrite module:
# cat /var/www/vhosts/example.com/test_rewrite/.htaccess RewriteEngine On RewriteRule ^.*$ mod_rewrite.php # cat /var/www/vhosts/example.com/test_rewrite/mod_rewrite.php <?php echo "Mod_rewrite is activated!"; ?>
and access the url
http://example.com/test_rewrite/