How to check whether mod_rewrite is enable on server?

Php.HtaccessMod RewriteUrl RewritingLightspeed

Php Problem Overview

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 and mod_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 find mod_rewrite there, is it because they are using lightspeed?

Is there any way to check? Please help me out. Thank you.

FYI: my .htaccess code is

Options -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]

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.

Php Solutions

Solution 1 - Php

from the command line, type

> sudo a2enmod rewrite

if the rewrite mode is already enabled, it will tell you so!

Solution 2 - Php

  1. To check if mod_rewrite module is enabled, create a new php file in your root folder of your WAMP server. Enter the following


  2. Access your created file from your browser.

  3. CtrlF to open a search. Search for 'mod_rewrite'. If it is enabled you see it as 'Loaded Modules'

  4. If not, open httpd.conf (Apache Config file) and look for the following line.

    #LoadModule rewrite_module modules/

  5. Remove the pound ('#') sign at the start and save the this file.

  6. Restart your apache server.

  7. Access the same php file in your browser.

  8. Search for 'mod_rewrite' again. You should be able to find it now.

Solution 3 - Php

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

Basically, this states to allow processing of all .htaccess directives.

Solution 4 - Php

This works on CentOS:

$ sudo httpd -M |grep rewrite_module

Should output rewrite_module (shared)

Solution 5 - Php


<VirtualHost *:80>
    <Directory ...>
        AllowOverride All

sudo a2enmod rewrite
sudo service apache2 restart

Solution 6 - Php

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!"; ?>

Solution 7 - Php

PHP's perdefined apache_get_modules() function returns a list of enabled modules. To check if mod_rewrite is enabled , you can run the following script on your server :


If the above example fails, you can verify mod-rewrite using your .htaccess file.

Create an htaccess file in the document root and add the following rewriteRule :

RewriteEngine on

RewriteRule ^helloWorld/?$ /index.php [NC,L]

Now visit , You will be internally forwarded to /index.php page of your site. Otherwise, if mod-rewrite is disabled , you will get a 500 Internel server error.

Hope this helps.

Solution 8 - Php


in_array('mod_rewrite', apache_get_modules())

returns true then mod-rewrite is enabled.

Solution 9 - Php

you can do it on terminal, either:

apachectl -M
apache2ctl -M

taken from 2daygeek

Solution 10 - Php

If this code is in your .htaccess file (without the check for 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]

and you can visit any page on your site with getting a 500 server error I think it's safe to say mod rewrite is switched on.

Solution 11 - Php

You can use php function


and check for mod_rewrite


Solution 12 - Php

If you are in linux system, you can check all enable modules for apache2(in my case) in the following folder:/etc/apache2/mods-available

cd /etc/apache2/mods-available

to type: ll -a
if you want to check the available modules for php (in this case php 7 ) folder /etc/php/7.0/mods-available

cd /etc/php/7.0/mods-available

to type: ll -a

Solution 13 - Php

I know this question is old but if you can edit your Apache configuration file to AllowOverride All from AllowOverride None

<Directory "${SRVROOT}/htdocs">
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    # The Options directive is both complicated and important.  Please see
    # for more information.
    Options Indexes FollowSymLinks

    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    AllowOverride All

    # Controls who can get stuff from this server.
    Require all granted

Solution 14 - Php

just make a new page and add this code

 if(!function_exists('apache_get_modules') ){ phpinfo(); exit; }
 $res = 'Module Unavailable';
 $res = 'Module Available';
<title>A mod_rewrite availability check !</title></head>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $res"; ?></p>

and run this page then find will able to know module is Available or not if not then you can ask to your hosting or if you want to enable it in local machine then check this youtube step by step tutorial related to enable rewrite module in wamp apache Wamp server icon -> Apache -> Apache Modules and check the rewrite module option

Solution 15 - Php

This code worked for me:

if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) echo "mod_rewrite enabled";
else echo "mod_rewrite disabled";

Solution 16 - Php

First you check if the module is installed

apachectl -M

It it does not shows on the list, you must activate it:

a2enmod rewrite

Now, restart your server and test

systemctl restart apache2

Solution 17 - Php

You just need to check whether the file is there, by typing

cat /etc/apache2/mods-available/rewrite.load

The result line may not be commented starting with #

Solution 18 - Php

I was having the exact problem, I solved it by clicking custom structure, then adding /index.php/%postname%/ and it works

Hope this saves someone the stress that I went through finding what the heck was wrong with it.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionknightriderView Question on Stackoverflow
Solution 1 - PhpKawaiKxView Answer on Stackoverflow
Solution 2 - PhpFadzly OthmanView Answer on Stackoverflow
Solution 3 - PhpJahmicView Answer on Stackoverflow
Solution 4 - PhpradtekView Answer on Stackoverflow
Solution 5 - PhpLukas LukacView Answer on Stackoverflow
Solution 6 - PhpwappyView Answer on Stackoverflow
Solution 7 - PhpAmit VermaView Answer on Stackoverflow
Solution 8 - PhpShivanshuView Answer on Stackoverflow
Solution 9 - PhpAdi PrasetyoView Answer on Stackoverflow
Solution 10 - PhpCliveView Answer on Stackoverflow
Solution 11 - PhpMiqdad AliView Answer on Stackoverflow
Solution 12 - PhpEzequiel De SimoneView Answer on Stackoverflow
Solution 13 - PhpExcellent LawrenceView Answer on Stackoverflow
Solution 14 - PhpHassan SaeedView Answer on Stackoverflow
Solution 15 - PhpKeinan GoichmanView Answer on Stackoverflow
Solution 16 - PhpFilipeView Answer on Stackoverflow
Solution 17 - PhpJoão Pimentel FerreiraView Answer on Stackoverflow
Solution 18 - PhpKyle SView Answer on Stackoverflow