Open any web browser browser and type following the URL, 'localhost/check. php'. It will display the PHP version details and Apache Configuration. In Apache Configuration, search for the Loaded Modules section, and there you will find all the modules that are enabled.
Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.
In order for Apache to understand rewrite rules, we first need to activate mod_rewrite . It's already installed, but it's disabled on a default Apache installation. Use the a2enmod command to enable the module: sudo a2enmod rewrite.
from the command line, type
sudo a2enmod rewrite
if the rewrite mode is already enabled, it will tell you so!
To check if mod_rewrite module is enabled, create a new php file in your root folder of your WAMP server. Enter the following
phpinfo();
Access your created file from your browser.
CtrlF to open a search. Search for 'mod_rewrite'. If it is enabled you see it as 'Loaded Modules'
If not, open httpd.conf (Apache Config file) and look for the following line.
#LoadModule rewrite_module modules/mod_rewrite.so
Remove the pound ('#') sign at the start and save the this file.
Restart your apache server.
Access the same php file in your browser.
Search for 'mod_rewrite' again. You should be able to find it now.
If you are using a virtual hosts configuration file, make sure the virtual host in question has the directive AllowOverride All
somewhere like this:
<VirtualHost *:80>
...
<Directory "directory/of/your/.htaccess">
AllowOverride All
</Directory>
</VirtualHost>
Basically, this states to allow processing of all .htaccess directives.
This works on CentOS:
$ sudo httpd -M |grep rewrite_module
Should output rewrite_module (shared)
If apache_get_modules() is not recognized or no info about this module in phpinfo(); try to test mod rewrite by adding those lines in your .htaccess file:
RewriteEngine On
RewriteRule ^.*$ mod_rewrite.php
And mod_rewrite.php:
<?php echo "Mod_rewrite is activated!"; ?>
console:
<VirtualHost *:80>
...
<Directory ...>
AllowOverride All
</Directory>
</VirtualHost>
sudo a2enmod rewrite
sudo service apache2 restart
If
in_array('mod_rewrite', apache_get_modules())
returns true
then mod-rewrite is enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With