473,624 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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 1654
On Aug 5, 11:09*am, Joe <j...@faceh.com wrote:
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?reque st=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.com wrote:
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?reque st=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.com wrote:
>>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?reque st=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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3683
by: Nel | last post by:
Just looking for some general advice on modifying the URL for php. I am using .htaccess to allow a web site to translate example.html to index.php?content=example (below) ErrorDocument 404 http://www.example.com RewriteEngine on RewriteRule ^/?(.*).html$ /index.php?content=$1
15
5136
by: Taki Jeden | last post by:
Hello everybody Does anybody know why w3c validator can not get pages that use 404 htaccess redirection? I set up two web sites so that clients request non-existent urls, but htaccess redirects calls to a script which parses the url and produces requested pages. It works fine with browsers, but when I try to validate the page I get a 404 error - which bewilders me, because I thought Apache does the redirection internally without sending...
2
2832
by: Geradeaus | last post by:
I use htaccess to rewrite the url using the following rules : RewriteRule ^(+)/(+)/(+)?$ index.php?lang=$1&page=$2&id=$3 The only problem I have is when http://www.domain.com/admin is given, the "admin" is used as $1. How can I define the rule for every word given except "admin" ? Thanks in advance!
5
1530
by: tommytx | last post by:
Is there any capability of decisions in htaccess. I know you can use in special situations, but I need something like: If a then b etc like in php. In other words I want to redirect the visitor to one of many pages via the htaccess file. Is there anyway to open a file and have a redirect to a different web page based on an input from a text file as below:
5
4993
by: deko | last post by:
I'm trying to redirect requests for /index.php to /mydirectory/index.php If I use an index file in / with only this line: <?php header("Location:http://www.mysite.com/mydirectory/"); ?> that seems to work. But can this be accomplished more efficiently with an htaccess rewrite?
3
1233
unicorn
by: unicorn | last post by:
hi, i want to prevent flashGet (or programs like this) from browsing my website and its content... is that possible? or if it is how... through .htaccess you can use rewrite engine like this: RewriteCond %{HTTP_USER_AGENT} ^FlashGet RewriteRule ^.* - i still can browse through... even folders of yahoo.com, so if it is possible to prevent it, then why yahoo didn't use it... i think this Rewrite Rule doesnt work. so is there any...
9
4388
by: invertigo | last post by:
Hello, Im using this .htaccess file to rewrite my websites URL. Reason i try to do this is to make it more SEO friendly. Code: -------------------------------------------------------- Options +FollowSymLinks RewriteEngine On RewriteBase mywebsite.awardspace.com
4
6688
by: adnanjunk | last post by:
Hi, Having a little issue with .htaccess not working on windows server. I have clean url's setup using the htaccess file, working fine on linux server. I have researched for a while and found .htaccess doesn't work on windows. Since this is a shared hosting i don't have access to httpd.conf so that i can edit it. I have been reading this forum about it. http://forum.mambo-foundation.org/showthread.php?t=1857
8
4049
hsriat
by: hsriat | last post by:
I had a .htaccess file for Rewrite on my server and was working fine. Now when I used the same code in 1and1 hosting, its not working. May be something is wrong or unexpectedly good happening inside 1and1 servers. Options +FollowSymLinks RewriteEngine on RewriteRule /id/(.*)/name/(.*) index.php?id=$1&name=$2 If anyone knows what's required to be changed to make it work on 1and1, please let me know.
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7168
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.