Forum Moderators: phranque

Message Too Old, No Replies

Apache config - mod_rewrite being gazumped by missing extensions

         

dcrombie

5:41 pm on Mar 20, 2005 (gmt 0)



I have a file:

/directory/file-name.html

and a mod_rewrite mapping:

/directory/file-name/ to /directory/file-name.html

That's all fine until the next rule which maps:

/directory/file-name/var1-var2/ to /directory/another-file.html?var1=var1&var2=var2

The problem is that on the server (not locally) this is being processed as a request for:

/directory/file-name.html

with the parameter:

"/var1-var2/"

As far as I can see, mod_rewrite isn't getting a look-in.

Anyone know a way to stop this?

jdMorgan

6:11 pm on Mar 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What version of Apache are you on?
Are the patterns in your rules properly anchored using "^" and "$"?
Who configured the server -- you, or your hosting company?

Jim

dcrombie

6:45 pm on Mar 20, 2005 (gmt 0)



Apache/1.3.26 (Unix) Debian GNU/Linux

Nothing 'unusual' has been done with the config - just turned on a few PHP options and set up some Aliases. Otherwise it's vanila-Apache. I control the server.

The same behaviour occurs on another Debian server: Apache/1.3.29 (Debian GNU/Linux).

My development platform (Darwin) behaves differently, as have other servers I've worked on.

RewriteRule ^directory/([-a-z]+)/?$ /directory/$1.html 
RewriteRule ^directory/[-a-z/]+/photo.jpg /directory/photo.jpg

As I said, mod_rewrite is being ignored, and the '/directory/file-name.html' file being executed with everything after 'file-name' appearing in $_SERVER["PATH_INFO"]...

jdMorgan

8:02 pm on Mar 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A common problem withj pre-2.0 Apache is an error in the LoadModule list order. Modules are execute in reverse order to the load order shown in the LoadModule list. If you have added php as a module after mod_rewrite, then php will execute before mod_rewrite, and so can have no effect.

It's a common problem, because people just assume they should add new stuff at the end of the LoadModule list, and then mod_rewrite, mod_auth, and a whole bunch of other stuff stops working for php files. Load php first, and then mod_rewrite can execute.

Apache 2.0 resolves this by letting modules declare their own priority, independent of the LoadModule order.

Adding php or any other non-Apache module makes your Apache installation non-plain-vanilla -- just adds a touch of flavor... ;)

Jim

dcrombie

8:52 am on Mar 21, 2005 (gmt 0)



That almost made sense ;) The problem is that on BOTH machines, the PHP module was listed last, and therefore loading first.

I've changed the order on the Debian server to put the rewrite_module last, and re-started Apache but the problem persists...

Something in Apache is allowing /filename to be recognised as a file request, wheras on other machines /filename.html is required, and /filename returns a 404. I just can't work out where that option is.

jdMorgan

2:08 pm on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Content negotion, maybe? Turn off Options Multiviews if you aren't using them.

Jim

dcrombie

2:28 pm on Mar 21, 2005 (gmt 0)



Perfect. Thanks!

For anyone who's interested, the information is here:
[httpd.apache.org...]
(under "Note on hyperlinks and naming conventions")