Forum Moderators: phranque
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
Welcome to WebmasterWorld!
The syntax of your RewriteRule is highly-suspect:
RewriteRule .+ %{c:/server/htdocs/}/bh101/index.php
I'd recommend that you test with the following change:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /bh101/index.php [L]
> 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
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!