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:
Array
(
[0] => core
[1] => mod_so
[2] => mod_watchdog
[3] => http_core
[4] => mod_log_config
[5] => mod_logio
[6] => mod_version
[7] => mod_unixd
[8] => mod_access_compat
[9] => mod_alias
[10] => mod_auth_basic
[11] => mod_auth_plain
[12] => mod_authn_core
[13] => mod_authn_file
[14] => mod_authz_core
[15] => mod_authz_groupfile
[16] => mod_authz_host
[17] => mod_authz_user
[18] => mod_autoindex
[19] => mod_cache
[20] => mod_cgi
[21] => mod_dav
[22] => mod_dav_fs
[23] => mod_dav_lock
[24] => mod_deflate
[25] => mod_dir
[26] => mod_env
[27] => mod_evasive20
[28] => mod_expires
[29] => mod_filter
[30] => mod_headers
[31] => mod_include
[32] => mod_mime
[33] => prefork
[34] => mod_negotiation
[35] => mod_php5
[36] => mod_proxy
[37] => mod_proxy_connect
[38] => mod_proxy_http
[39] => mod_remoteip
[40] => mod_reqtimeout
[41] => mod_rewrite
[42] => mod_setenvif
[43] => mod_slotmem_shm
[44] => mod_socache_memcache
[45] => mod_socache_shmcb
[46] => mod_speling
[47] => mod_ssl
[48] => mod_status
[49] => mod_userdir
[50] => mod_vhost_alias
[51] => mod_xml2enc
)
If your
mod_rewrite module is configured correctly you'll
see it in the php array containing
all your apache loaded modules.
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
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 On RewriteOptions Inherit RewriteRule
^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!