Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem

         

ThomThom

8:53 am on Sep 10, 2007 (gmt 0)

10+ Year Member



I'm adding a download section to my site. I want to keep track of the downloads so I created a proxy file that takes one variable 'file' which specifies the file to be downloaded. It logs the download to the database and then fetches the file. The proxy file is named 'd.php'

The problem is that I'm trying to create nice URL for it without any query strings.

Example:
[download.example.net...] will redirect to d.php?file=test.txt

[download.example.net...] will redirect to d.php?file=test/foo.txt

I created a .htaccess file like this:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)$ d.php?file=$1

For some reason I can't understand, the d.php's 'file' argument is populated with 'd.php'. At least that's what happends on my local test server.

---

On my live site, I get a 500 error with the same .htaccess file. I did some testing and found some odd results.

RewriteRule ^(.+)$ d.php?file=$1 <- 500 error
RewriteRule ^([a-zA-Z0-9/_\-]+)$ d.php?file=$1 <- no error
RewriteRule ^([.a-zA-Z0-9/_\-]+)$ d.php?file=$1 <- 500 error

It appears that the period in the regular expression causes a 500 error on my live site.

[edited by: jdMorgan at 11:08 pm (utc) on Sep. 10, 2007]
[edit reason] example.net [/edit]

ThomThom

9:39 am on Sep 10, 2007 (gmt 0)

10+ Year Member



I tried this to see if it'd stop it from forwarding 'd.php' as the 'file' argument, but is didn't work this either.

RewriteCond %{REQUEST_URI}!^/d\.php
RewriteRule ^(.+)$ d.php?file=$1

jdMorgan

12:47 pm on Sep 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That should have fixed the looping problem you described.

What specific error did you get? And did you flush your browser cache before testing the change? If not, the browser may just have given you the previously-cached response.

Jim

ThomThom

3:43 pm on Sep 10, 2007 (gmt 0)

10+ Year Member



The problem was locally. My test server was set up as [localhost...]

which meant that Request URI contained "/download.example.net/test/foo.txt" so the exclusion never triggered.

And it appears that the live server, running Apache 1.3, would throw a 500 error on the loop, but my local test server running Apache 2.0 seemed to detect the loop and exit it instead of throwing an error.

I've got it working now.

[edited by: jdMorgan at 11:09 pm (utc) on Sep. 10, 2007]
[edit reason] example.net [/edit]