Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

up vote 14 down vote accepted

Have you tried using the QSA (Query String Append) flag?

RewriteRule ^static/([^/]+)/([^/]+) /static.php?sISOCode=$1&sPage=$2 [QSA]


EDIT, AND ACTUAL ANSWER BELOW:

This problem is caused by Apache's mod_negotiation, in particular the MultiViews option you are using:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

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.

share|improve this answer
1  
I wanted to suggest that too, but what I don't get: It should not be needed - at least I don't think so after reading the manual. Curious how this question will turn out –  pilif Apr 30 '09 at 8:34
1  
The QSA flag changes nothing in this situation, unfortunately. The GET parameteres are appended by the rule, not from the original URL. –  Vegard Larsen Apr 30 '09 at 8:35

The solution was to change the Apache configuration, like this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName project.example.com

        DocumentRoot /home/veg/workspace/project
        <Directory /home/veg/workspace/project>
                Options FollowSymLinks
                # 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>

I don't know why this works, however

share|improve this answer
2  
See my revised previous answer for an explanation: serverfault.com/questions/60/… –  Aron Rotteveel Apr 30 '09 at 9:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.