Page 1 of 1

Apache URL Rewriting weirdness

Posted: Sun Aug 09, 2009 10:35 am
by Jammerious
Hi,
I was wondering, how on Earth does Apache do these rewrites, without them being set in apache2.conf file?
My example:

Code: Select all

foo/
  .htaccess
  test.php
I open the browser and type:
http://server/foo/test
And it shows the test.php page. I want to prevent this.
Because, having:

Code: Select all

RewriteRule ^test/([0-9]{2})$ test.php?projectId=$1 [L]
And trying to visit:
http://server/foo/test/22
doesn't fall into the RewriteRule -> if I print_r($_GET) in test.php, nothing is seen, $_GET is empty.

Re: Apache URL Rewriting weirdness

Posted: Sun Aug 09, 2009 11:21 am
by VladSun
It's not mod_rewrite, but mod_negotiation

http://httpd.apache.org/docs/1.3/conten ... ation.html

Just turn off Multiviews option.

Re: Apache URL Rewriting weirdness

Posted: Sun Aug 09, 2009 2:08 pm
by Jammerious
Hi,
thanks for pointing me in the right direction.
I tried adding:

Code: Select all

<Directory /var/www>
  Options All
</Directory>
to apache2.conf, restarted it with no error and it still had multiview enabled, although in the docs it clearly says that this should make MultiView off.
http://httpd.apache.org/docs/2.2/mod/core.html#options

The correct way of doing this is to add the line:

Code: Select all

Options -MultiViews
to the .htaccess file.

Thanks =)

Re: Apache URL Rewriting weirdness

Posted: Sun Aug 09, 2009 4:17 pm
by Jammerious
One more thing.. :(
All my relative URLs in the html document don't work with this enabled.
E.g.:

Code: Select all

<img src="images/icons/check_10.png"/>
Tries to locate the image at http://server/test/images/icons/check_10.png
instead of
http://server/images/icons/check_10.png

What can I do besides having:

Code: Select all

<img src="../images/icons/check_10.png"/>
?

EDIT:
Oh OK, just realised this is more of a browser issue, $_SERVER['SCRIPT_FILENAME'] shows the correct route, so nothing to be done on the serverside?

Re: Apache URL Rewriting weirdness

Posted: Mon Aug 10, 2009 4:14 pm
by Jammerious
Well, using:

Code: Select all

<base href="http:/server/" />
I solved this problem, hope there's nothing wrong with doing so :)