How to check whether mod_rewrite is enable on server?
Solution 1
from the command line, type
sudo a2enmod rewrite
if the rewrite mode is already enabled, it will tell you so!
Solution 2
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.
Solution 3
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.
Solution 4
This works on CentOS:
$ sudo httpd -M |grep rewrite_module
Should output rewrite_module (shared)
Solution 5
console:
<VirtualHost *:80>
...
<Directory ...>
AllowOverride All
</Directory>
</VirtualHost>
sudo a2enmod rewrite
sudo service apache2 restart
knightrider
Updated on September 23, 2021Comments
-
knightrider over 2 years
Currently I am using the hosting with lightspeed server. Hosting says
mod_rewrite
is enabled but I can't get my script working there. Whenever I try to access the URL, it returns 404 - not found page.I put the same codes at another server which is running with Apache. It's working over there. So I guess, it's the
.htaccess
andmod_rewrite
issue.But Hosting support is still insisting with me that their mod_rewrite is on, so I would like to know how can I check whether it's actually enabled or not.
I tried to check with
phpinfo()
, but no luck, I can't findmod_rewrite
there, is it because they are usinglightspeed
?Is there any way to check? Please help me out. Thank you.
FYI: my
.htaccess
code isOptions -Indexes <IfModule mod_rewrite.c> DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] </IfModule>
I tried like this also
DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
But same result.
-
Clive over 12 yearsSo you can access some pages on the site without a 500 error? That would generally mean if the .htaccess file is being read that mod_rewrite must be switched on. However the .htaccess might not be being read...try writing some nonsense characters at the top of your .htaccess file, this will cause the connection to die with a 500 server error if Apache is actually reading the file. If it is being read, could you give an example of a URL you think should work but doesn't?
-
knightrider over 12 yearsthe problem is, it's not apache server, it's lightspeed. I never get 500 error, all i get is 404 error. That's why I am doubting that .htaccess is not enable.
-
Clive over 12 yearsMost likely yes, I'd try putting the nonsense characters in to .htaccess and see if you get the 500 error when you go directly to a non-rewritten page (e.g. index.php). If not, it might be worth posting a new question asking how to enable .htaccess with Lightspeed
-
MrWhite almost 12 yearsapache_get_modules() will only work if PHP is running as an Apache module. The OP states that PHP is running on Lightspeed.
-
MrWhite almost 12 yearsI believe phpinfo() reports the Apache Loaded Modules when PHP is itself being run as an Apache module. The OP states that PHP is running on Lightspeed, which has its own mod_rewrite compatible rewrite engine.
-
Fernando Sanchiz about 8 yearsI've tried a lot to solve this and then when try this it works for me. I have the last apache and ubuntu now.
-
Greg Noe over 7 yearsFor the first step I had to enter: <?php echo phpinfo(); ?>
-
Nishant Ghodke over 7 yearsThanks. I owe you a Budweiser. <3
-
Shakeel Ahmed almost 7 yearsPerfect one line solution to check rewrite module enabled or not via PHP codes.
-
Adi Prasetyo over 6 yearsi use 7.2, apache_get_modules got undefined. Do i have to restart apache2 after editing
.htaccess
? -
João Pimentel Ferreira over 6 yearswhat does it mean the
...
in<Directory ...>
? What shall I put there? the directory where .htaccess is? -
João Pimentel Ferreira over 6 yearsyes indeed, the ... should mention between quotes "..." the directory where .htaccess is
-
Rory O'Kane over 6 yearsNote that this method will not work if you are running PHP as a CGI application (which is the case if
phpinfo()
’s “Server API” field shows “CGI/FastCGI”).phpinfo()
won’t list the enabled modules. In that case, see How to check for mod_rewrite on PHP CGI. -
D. Dan over 5 yearsIt had. I had the conf file copied from the server, and while I had changed the
ServerName
, I had not changed the directory name, after that and an apache restart it was ok. -
John T. over 5 yearsThis is the best way to do it on CentOS, assuming you have ssh access. Thanks, @radtek!
-
Sinthia V over 5 yearsRichardIf this answer worked for you and solved your problem you should mark it as correct and award @Jahmic his due.
-
androsfat almost 5 yearsIn Debian 9, it does work but you must be logged in as root or use
sudo
-
MindRoasterMir about 4 yearsIt is a good idea to tell the exact name and when possible the location of the file that need to be changed. It will be helpful for the newcomers. Thanks
-
MindRoasterMir about 4 yearsIt should also be kept in mind that the changes take effect only after you have restated your apache. thanks
-
Amit Verma almost 4 yearsNo you don't need to restart your server when using htaccess.
-
Avatar about 2 years
sudo: a2enmod: command not found
NOT enabled. 🙂 ... Install viasudo a2enmod rewrite
and restart serversudo service apache2 restart
. -
Leandro Bardelli about 2 yearswill return "Module rewrite already enabled" if it's ok.