Howto check if mod_rewrite is installed and loaded in Apache 2.x and serving directories correctly

During my professional experience as a system administrator, it was a common misfortune in newly
configured unix servers mod_rewrite not to be serving .htaccess files.
Everytime I had to fix issue in which mod_rewrite was not working I loosed a lot of my precious time
The same story happened once again I had to check why mod_rewrite is not configured correctly and I cannot
apply some redirection rules in WordPress necessery for me
to exercise some SEO on my wordpress blog .
Therefore this time I decided to blog a step by step check on in order to:

1. Determine if mod_rewrite is installed & loaded correctly in Apache
2. Find out if mod_rewrite is configured to serve .htaccess files correctly
Going through this two scenarios I would be able to determine why I cannot get wordpress SEO optimization
mod_rewrite redirection rules to work as they should.
Okay, so let’s go through the two scenarios:

1. Here is a tiny script in PHP to determine if mod_rewrite is installed and loaded in Apache correctly
To use the script save it somewhere in your Domain document root with a .php extension
Here is the code of the script as well:

< ?phpprint_r(apache_get_modules());?>

If your mod_rewrite module is configured correctly you’ll see it in the php array containing
all your apache loaded modules.

Without PHP from the shell in order to get installed Apache modules on Linux, the following command applies:

apache2ctl -t -D DUMP_MODULES

For apache 2.2.x
httpd (or apache.exe) -M will show static and shared modules loaded via LoadModule.
httpd -l will show only static (compiled in) modules

For apache 2.0.x
httpd (apache.exe) -l is available but -M is not.
You will need to manually check the LoadModule directives and the files.

2. Now we continue, further on with another script that has to be installed somewhere in Apache’s DocumentRoot
I decided to install it in a directory /test/ so in my case it’s installed in www.pc-freak.net/test/
Here is a link to the script you need to find out if mod_rewrite is configured to serve .htaccess files for your preferred domain name’s DocumentRoot.

Now save this file and again make sure it has a .php extension.

Now you need to create an .htaccess file in the directory where you have rewrite.php file stored.
The content of the .htaccess file should be the following:

RewriteEngine OnRewriteOptions InheritRewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

Make sure the permissions of the .htaccess are correct, for example the file should have at least read
permissions for your webserver.
So let’s execute:

chmod a+r .htaccess to ensure the newly created file has proper permissions
So let’s check if mod_rewrite is enabled for my domain DocumentRoot by visiting:
this link
Hopefully if all is okay you’ll see:
Congratulations!! You are using Apache mod_rewrite whenever you press the TEST2 link
on the upmentioned webpage.

In case if you get a 404 error message, then most probably you don’t have mod_rewrite configured
to serve .htaccess files for your domain.
This often happens because of missing:
AllowOverride All in your main Directory directives in your webserver configuration file.
In my case I had a problem where mod_rewrite rules were not red from the .htaccess file:
To solve my issue I had to change:

Directory /
AllowOverride None
Order Deny,Allow
Deny from all
/Directory
in my httpd.conf to

Directory /
AllowOverride All
Order Deny,Allow
Deny from all
/Directory

So well, That’s all Folks!

Share this on

More helpful Articles

Download PDFDownload PDF

Tags: , , , , , , , , , ,

14 Responses to “Howto check if mod_rewrite is installed and loaded in Apache 2.x and serving directories correctly”

  1. Hipolito M. Wiseman says:
    Opera 8.50 8.50 Opera 8.50 8.50 Windows XP Windows XP
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50

    Good post! I ‘ve found something like this time to time. Thank you.

    View CommentView Comment
  2. Cyncfoolo says:
    Internet Explorer 7.0b Internet Explorer 7.0b Windows Vista Windows Vista
    Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)

    Hey Blogger,When you write some blogs and share with us,that is a hard work for you but share makes you
    happly right?,yes I am a blogger too,and I wanna share with you my method to make some extra cash,not too much
    maybe $100 a day,but when you keep up the work,the cash will come in much and more.

    good luck and cheers!

    View CommentView Comment
  3. Plastic Storage Boxes says:
    Firefox 2.0.0.6 Firefox 2.0.0.6 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6

    Useful article as always at this web site. I found it under my bookmarks, probably my wife bookmarked it.

    View CommentView Comment
  4. claudius tiberiu iacob says:
    Firefox 3.6.10 Firefox 3.6.10 Windows Vista Windows Vista
    Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10

    OK,
    The “tiny script in PHP…” link isn’t actually downloadable (the link serves the output of the script instead of the script itself), so please put these lines in an empty PHP file and use that file instead.

    credits: http://www.phpbuilder.com/manual/function.apache-get-modules.php

    View CommentView Comment
    • admin says:
      Epiphany 2.30.6 Epiphany 2.30.6 Debian GNU/Linux x64 Debian GNU/Linux x64
      Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6

      Hi Claudius,

      Thanks for the tip. I’ve fixed the file to be downloadable in the post.
      It was a problem my apache php interpreter was interpreting the file.

      Regards,
      Georgi

      View CommentView Comment
  5. Brad says:
    Firefox 3.6.14 Firefox 3.6.14 Windows XP Windows XP
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14 ( .NET CLR 3.5.30729; .NET4.0E)

    What about later versions of apache? My http.conf looks like this

    allow from all
    Options +Indexes

    I can’t get sef url’s working to save my life.

    Brad

    View CommentView Comment
  6. zu says:
    Firefox 4.0 Firefox 4.0 Windows 7 x64 Edition Windows 7 x64 Edition
    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0

    Thanks a mil for this tip – the “AllowOverride All” got the .htaccess file working for me.

    Wish you a happy and healthy life!! 🙂

    View CommentView Comment
    • admin says:
      Epiphany 2.30.6 Epiphany 2.30.6 Debian GNU/Linux x64 Debian GNU/Linux x64
      Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Version/5.0 Safari/531.2+ Debian/squeeze (2.30.6-1) Epiphany/2.30.6

      I’m glad it helped 🙂

      View CommentView Comment
  7. Andy says:
    Google Chrome 15.0.874.106 Google Chrome 15.0.874.106 Windows XP Windows XP
    Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2

    Thank you Sir. The AllowOverride None had got me too. 

    View CommentView Comment
  8. junkiest says:
    Firefox 4.0.1 Firefox 4.0.1 Windows 7 Windows 7
    Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1

    Nice tutorial…. thanks !!!

    View CommentView Comment

Leave a Reply

CommentLuv badge