Apache URL Rewriting weirdness

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

Apache URL Rewriting weirdness

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Apache URL Rewriting weirdness

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

Re: Apache URL Rewriting weirdness

Post 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 =)
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

Re: Apache URL Rewriting weirdness

Post 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?
User avatar
Jammerious
Forum Commoner
Posts: 59
Joined: Sat Jun 27, 2009 11:30 am
Location: Slovenia (EU)

Re: Apache URL Rewriting weirdness

Post by Jammerious »

Well, using:

Code: Select all

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