Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite behaving differently on two servers

         

samJL

4:59 pm on Apr 9, 2011 (gmt 0)

10+ Year Member



I have written some mod_rewrites that work fine on one server, but not another


RewriteEngine on
RewriteRule ^submit/bulk/?$ "submit_bulk.php"
RewriteRule ^submit/?$ "submit.php"


mod_rewrite is working in general, for example going to site/about brings me to about.php on Server A and on Server B

But something strange is happening on Server B when the mod_rewrite goes another level forward

For example, on Server A, when I visit site/submit/bulk it brings me to submit_bulk.php, but when I visit that same location on Server B it brings me to submit.php. It's like on the second server it picks the first mod_rewrite match (/submit) and doesn't keep looking for the actual match (/submit/bulk).

Can you see what might be wrong?

Thank you

g1smd

6:58 pm on Apr 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add the [L] flag to both rules.

Delete the quotes from both targets.

Did you want an external redirect or an internal rewrite here?

If you want an internal rewrite then be aware that your code promotes Duplicate Content. It allows URL requests both with and without a trailing slash to serve content. You should have a preceding rule that externally redirects "with trailing slash" to "without trailing slash". The internal rewrite should only be allowed to proceed if the URL request is without trailing slash.

samJL

7:50 pm on Apr 10, 2011 (gmt 0)

10+ Year Member



Thank you for your reply, I was going for internal re-writes

The "without trailing slash" point is a good idea and I will make those changes

Adding L though didn't seem to make a difference - as it turns out my problem has to do with the fact that MultiViews was turned on by default with my Apache2 install

By adding "Options -MultiViews" my mod_rewrites are now working as I expected

g1smd

7:55 pm on Apr 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, MultiViews is often the problem, but you didn't post that bit of the code.

DO add the [L] flag to every RewriteRule unless you know exactly why it should not be added.

samJL

8:03 pm on Apr 10, 2011 (gmt 0)

10+ Year Member



I didn't know enough to post the 000-default file, where MultiViews is being enabled

Can you explain the significance of the [L] flag? I will add it

g1smd

8:36 pm on Apr 10, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If THIS rule matches, don't process any further mod_rewrite rules for this request.

Omitting the [L] flag can lead to weird and unwanted difficult-to-diagnose side effects.

The [L] flag is not required when the [F] or [G] flags are used.

samJL

11:00 pm on Apr 10, 2011 (gmt 0)

10+ Year Member



ok great, thanks again