Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Check For Module Presence in .htaccess

5 Responses »

One of my favorite Apache modules is mod_rewrite. mod_rewrite allows me to manipulate page URLs so that I can search engine friendly URLs. Not every Apache server has the mod_rewrite module installed so you will want to add a conditional statement within your .htaccess file to make sure it's there.

The .htaccess

#Wordpress's .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

If the "mod_rewrite.c" module is present, that means that mod_rewrite is available and will be used. If not, the mod_rewrite code will be ignored. Using this conditional statement will prevent 500 Internal Server Errors.

Discussion

  1. jeff hartman
    November 7, 2008 @ 11:23 am

    So what is the fallback for when it is not available? If you do this you need to make sure your code has a way to handle it, especially if your mod_rewrite conditions are passing get vars.

    I personally would like to know about a 500 server error so that I could fix the problem.

  2. shinzies
    November 25, 2008 @ 3:45 am

    Would it be fine to include this code into httpd.conf itself?
    Or is that a bad idea?

    Thanks David.

  3. shinzies
    November 25, 2008 @ 4:28 am

    Nope, the answer is it is bad idea because, Rewrite Base is only valid per-directory config files.

    :D

  4. October 14, 2009 @ 2:07 am

    how to make a link like this rerwiteRule index.php? module = article & id = 5

    thanks

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!