Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite running page twice?

php script reports it is running twice with mod_rewrite

         

stevierar

11:07 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Hihi,

I'm making a site and I'm at a bit of a loss!

I have the following .htaccess;

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d

RewriteRule .+ %{c:/server/htdocs/}/bh101/index.php

-

The plan being a request of say;

[localserverip...]

Is always passed back to the index.php, which looks at the address and decides which page to go to.

This has all been working fine.. until I wrote in some statistics logging.

Every page registers twice, it's nothing wrong with my script! If I go to a page via the mod_rewrite the hit is logged twice, if I go directly (as in: index.php?foo=blah) - it only registers one hit.

I read somewhere that mod_rewrite works by basically changing the address and requesting it again, but I can't believe it'd allow the (first) request to be passed to PHP?

This is a local test-bed server, so I'm equally willing to believe I have my apache set up wrong; but I've never had a problem before!

Is this usual behaviour for the .htaccess quoted above? If it is not - I may upload it to my data centre and see if it is just my poor little neglected server here! :D

Oh - and just to say (to show my level of understanding on the syntex of the .htaccess anyway)! The mod_rewrite above is one a mate wrote for me a year ago, regexp (if that's even it!) terrifies me so much I just use the same .htaccess on every site - but with the directories changed! ^.^

Oh - and PSS I guess - the c:/server/htdocs/ instead of DOCUMENT_ROOT is just so I don't get muddled going between remote and local servers!

Hope someone can get back to me,
Thanks,
Stevierarx

jdMorgan

1:04 am on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stevierar,

Welcome to WebmasterWorld!

The syntax of your RewriteRule is highly-suspect:


RewriteRule .+ %{c:/server/htdocs/}/bh101/index.php

The "%{}" container is used only for server-defined variables, and "c:/server/htdocs/" is certainly not one of those. mod_rewrite alreadt takes your DocumentRoot configuration into account, so there is no need to specify it in the substitution URL-path.

I'd recommend that you test with the following change:


RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /bh101/index.php [L]

If this doesn't fix your problem, let us know. There are some other tests you could also do.

> I read somewhere that mod_rewrite works by basically changing the address and requesting it again, but I can't believe it'd allow the (first) request to be passed to PHP?

No. mod_rewrite intercepts the incoming request, and modifies the URL before any content-handlers or scripts are invoked (assuming a properly-configured server).

Jim

stevierar

4:14 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



Hi, thanks for your reply!

I made the change you suggested, and the same thing is happening! It's very bizarre @.@!

Just a note to say that this is in a .htaccess file in the directory in question, not in httpd.conf - if that makes any difference.

Any other ideas? :D

Thankyou!
Steve

stevierar

4:28 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



Hahaha, correction: it's now doing it three times! :D

Edit: please disregard this thread for now, I think it may be a problem with one of my scripts - I've identified it down to a function that seems to be repeating the page some how! THanks :D

stevierar

4:45 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



And fixed.. this is embarassing!

I had an image in the page that was hidden away from when I was making the initial design. I didn't update the address for that, so it was trying to open /shop/details/image.jpg which obviously wasn't there, as it was a mod_rewrite-d address. So it got passed to my index.php, which read the first two bits and handed it to the appropiate page.

Had to delve into my access logs to find that one! :D

Thanks for your help anyway guys! ^.^ I shall probably stick around here!