Bad Request Error with apache mod_rewrite

If you use apache module mod_alias together with module mod_rewrite, you probably encounter “Bad Request” error if the settings are not correctly configured.


For example, if you want to make the folder “/opt/mysite_v1.2″ have the alias as “/mysite” so it can be accessed as http://www.mydomain.com/mysite. And you want to have clean url “/mysite/page1″ mapped to “/mysite/index.php?p=page1″.

To define the alias, just add the following in the httpd.conf file:

Alias /mysite/ “/opt/mysite_v1.2/”
<Directory “/opt/mysite_v1.2/”>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>

To allow clean URL. you need to have the following in the “.htaccess” file in the folder “/opt/mysite_v1.2″

RewriteEngine On
# Rewrite base
RewriteBase   /mysite

#  now the rewriting rules
RewriteRule   ^([0-9a-zA-Z_]+)$  index.php?p=$1

Please NOTE that “RewriteBase” Directive is very essential. Without it, you will get the well known “Bad Request” Error.

More information can be found in Apache mod_rewrite documentation.

Leave a Reply

Spam Protection by WP-SpamFree