471,066 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

.htaccess style rewrite with php

Joe
Hello, I currently have a file system where images and assets are
stored in a directory like this:

http://www.domain.com/assets/media/C...R/CLIENT_FILES

Which holds many differents clients assets, seperated by CLIENT_NAME.
This is not very elegant when my clients want to provide links to
their files, so I want a way of using php (or any other method you
might suggest) to make the following work:

http://www.domain.com/media/CLIENT_DIR/CLIENT_FILES

This cannot be a simple redirect as that would not work for including
files in htm templates. It has to do a similar thing as .htaccess
rewrite, however I cannot use .htaccess since the client name is
dynamic.

Anybody any thoughts?
Aug 5 '08 #1
3 1527
On Aug 5, 11:09*am, Joe <j...@faceh.comwrote:
http://www.domain.com/media/CLIENT_DIR/CLIENT_FILES

This cannot be a simple redirect
When configured specifically, you can make a page media.php which is
also used when
http://www.domain.com/media.php/CLIENT_DIR/CLIENT_FILES
is accessed. You can then parse the URL from the $_SERVER array.
Anybody knows how this is called or configured?

Of course, you can use rewriting to get rid of the .php, so that you
rewrite
media/bla to media.php/bla

Now that I think of it, you can also rewrite
media/bla to media.php?request=bla
So that you can just get the request out of $_GET. However, this gives
problems with some characters in filenames such as &.
Aug 5 '08 #2
Joe
On Aug 5, 11:21 am, Sjoerd <sjoer...@gmail.comwrote:
On Aug 5, 11:09 am, Joe <j...@faceh.comwrote:
http://www.domain.com/media/CLIENT_DIR/CLIENT_FILES
This cannot be a simple redirect

When configured specifically, you can make a page media.php which is
also used whenhttp://www.domain.com/media.php/CLIENT_DIR/CLIENT_FILES
is accessed. You can then parse the URL from the $_SERVER array.
Anybody knows how this is called or configured?

Of course, you can use rewriting to get rid of the .php, so that you
rewrite
media/bla to media.php/bla

Now that I think of it, you can also rewrite
media/bla to media.php?request=bla
So that you can just get the request out of $_GET. However, this gives
problems with some characters in filenames such as &.
I can parse the $_SERVER['REQUEST_URI'] as you suggested to get to the
desired file, however the issue with that is how to return image
files, or pdf files, or .doc files, etc. as that file type. ie. if it
links to a .jpg file, return a .jpg file. The only way I can think to
do it is redirect to that file, which is not what I want. I think it
is something to do with setting the file type in the php header, but
not sure.
Aug 5 '08 #3
Joe wrote:
On Aug 5, 11:21 am, Sjoerd <sjoer...@gmail.comwrote:
>On Aug 5, 11:09 am, Joe <j...@faceh.comwrote:
>>http://www.domain.com/media/CLIENT_DIR/CLIENT_FILES
This cannot be a simple redirect
When configured specifically, you can make a page media.php which is
also used whenhttp://www.domain.com/media.php/CLIENT_DIR/CLIENT_FILES
is accessed. You can then parse the URL from the $_SERVER array.
Anybody knows how this is called or configured?

Of course, you can use rewriting to get rid of the .php, so that you
rewrite
media/bla to media.php/bla

Now that I think of it, you can also rewrite
media/bla to media.php?request=bla
So that you can just get the request out of $_GET. However, this gives
problems with some characters in filenames such as &.

I can parse the $_SERVER['REQUEST_URI'] as you suggested to get to the
desired file, however the issue with that is how to return image
files, or pdf files, or .doc files, etc. as that file type. ie. if it
links to a .jpg file, return a .jpg file. The only way I can think to
do it is redirect to that file, which is not what I want. I think it
is something to do with setting the file type in the php header, but
not sure.
Perhaps what you want to do is read in the file from a protected
location and print the header and then the file. Include the file type,
disposition and name in the header.

Jeff
Aug 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Nel | last post: by
15 posts views Thread by Taki Jeden | last post: by
2 posts views Thread by Geradeaus | last post: by
unicorn
3 posts views Thread by unicorn | last post: by
9 posts views Thread by invertigo | last post: by
4 posts views Thread by adnanjunk | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.