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:
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:
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 / in my httpd.conf to
Deny from all
Deny from all
So well, Thatâ€™s all Folks!