I'm having trouble setting up Apache with mod_rewrite on my development machine. Mod_rewrite is active, and works well for some rules. Some rules do not work as intended, like this one:
RewriteRule ^static/([^/]+)/([^/]+) /static.php?sISOCode=$1&sPage=$2
In static.php I do this (for debugging):
<?php
print_r($_GET); print_r($_POST); print_r($_SERVER); die();
Which prints (removed some items from the $_SERVER array):
Array
(
)
Array
(
)
Array
(
[SERVER_SIGNATURE] => <address>Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch Server at alpha.prove.no Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /home/veg/workspace/project
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /home/veg/workspace/project/static.php
[REMOTE_PORT] => 38954
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /static/no/startCar
[SCRIPT_NAME] => /static.php
[PATH_INFO] => /no/startCar
[PATH_TRANSLATED] => redirect:/index.php/startCar
[PHP_SELF] => /static.php/no/startCar
[argv] => Array
(
)
[argc] => 0
)
Somehow the GET parameters set according to the rule is not getting through. The same .htaccess file is in use on other setups, and works well. The Apache configuration for this virtual domain:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName project.example.com
DocumentRoot /home/veg/workspace/project
<Directory /home/veg/workspace/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
The access log and error log outputs nothing when this happens. Any ideas appreciated.
An example of a rule that works, for the same file:
RewriteRule ^faq/?$ /static.php?sISOCode=no&sPage=faq
Have you tried using the QSA (Query String Append) flag?
EDIT, AND ACTUAL ANSWER BELOW:
This problem is caused by Apache's mod_negotiation, in particular the MultiViews option you are using:
Enabling Multiviews tells Apache to guess which file to use when the URI does not actually point to an existing location.
Solution:
Disable multiviews by either using
-MultiViews
in your .htaccess or leaving it out all together.The solution was to change the Apache configuration, like this:
I don't know why this works, however
Disable -MultiViews in your htaccess file somthing like below
this will solved the issue