Forum Moderators: phranque

Message Too Old, No Replies

Matching IP to file name

         

Kode_Kid

4:21 am on Aug 15, 2005 (gmt 0)

10+ Year Member



Hi All,

I don't know if this can be done in htaccess, but here goes ...

I have a web site where you can request to see a video. When you select your video my scripts create your video in a public directory using your IP address as part of the file name. As an example, if i were to request a video the video would be named "www.mysite.com/videos/70.32.9.115.rm".

Here is what i'm trying to do: Is there some way to write an htaccess file so that the requesters IP address is automatically matched up with the correct video? In other words, using the web address above, i'd like to be able to type "www.mysite.com/videos/" into my browser and have an htaccess file automatically forward me to the video file named after my IP address. Conversely, it would be nice if the htaccess file would recognize when a file named after my IP address does not exist and forwards the user back to the video request page.

Any ideas? I've been working on this for hours and i don't have a clue.

Paul

jdMorgan

4:40 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Paul,

This sounds like a very simple application of mod_rewrite to insert the variable %{REMOTE_ADDR} into the requested URL, and serve the request from the resulting location. If you are already using mod_rewrite, then it's one line of code:


RewriteRule ^/videos/video\.rm$ /videos/%{REMOTE_ADDR}.rm [L]

Note that I inserted a 'dummy' filename of "video" to take the place where the IP address will go. You can do that differently if you prefer.

Reference documents for mod_rewrite are cited in our forum charter [webmasterworld.com].

Jim

Kode_Kid

6:43 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Hmmm, maybe i'm doing something wrong. my entire htaccess file looks like this:

AuthUserFile /dev/null
AuthGroupFile /dev/null
RewriteEngine On
RewriteRule ^/test/some.gif$ /test/%{REMOTE_ADDR}.gif [L]

I also tried it with the back slash like this:

AuthUserFile /dev/null
AuthGroupFile /dev/null
RewriteEngine On
RewriteRule ^/test/some\.gif$ /test/%{REMOTE_ADDR}.gif [L]

But no go. The problem is the "%{REMOTE_ADDR}." is not being translated into a remote address. It comes out exactly as written: %{REMOTE_ADDR}.

I'll keep hammering away at it.

Paul

JJao

8:15 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



I'm not a .htaccess expert (far from it), and because of that I would avoid this area myself and try a different approach.
If your script creates a video, why not create a unique directory as well, with a unique .htaccess file in it? (can .htaccess be used that way?)
Then redirecting your visitor could be done by a serverside or clientside script.
But then again, I might be missing your point completely!

jdMorgan

10:14 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In .htaccess, delete the leading slash on the RewriteRule pattern:

AuthUserFile /dev/null
AuthGroupFile /dev/null
RewriteEngine On
RewriteRule ^test/some\.gif$ /test/%{REMOTE_ADDR}.gif [L]

If the Remote_Addr variable remains as a literal string, then contact your host -- This is a major show-stopper.
You may also need to add Options +FollowSymLinks ahead of RewriteEngine on

Jim