Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with a Url Rewriting

Posted on 2009-04-17
4
Medium Priority
?
368 Views
Last Modified: 2012-05-06
Hi!

I've a little problem,

I've URL like http://myadress.com/folder/file.png?id=001d5000015b

And I would redirect this to a php script, so I've a .htaccess

RewriteEngine on

RewriteRule ^(.*)\?id=([0-9a-f]+)$ ../fileGiver.php?file=$1&id=$2 [L]

But this isn't recognized.

If I use instead an url like this:
I've URL like http://myadress.com/folder/file.png/001d5000015b

The last information is a mac adresse given by the client to authenticate her.

and the htaccess:

RewriteEngine on
RewriteRule ^(.*)/([0-9a-f]+)$ ../fileGiver.php?file=$1&id=$2 [L]

And this works good, but the problem is that this system is destinate to an other system, and the system think that this is a folder and don't do the good action.

So what is the problem in my first regexp? Is the "?" changed to something that her html char?
0
Comment
Question by:Nargzul
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 24171807
The QueryString is not available in a rule-pattern. You'll need a condition.
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([0-9a-f]+)$
# restricting to png; it is not recommended to use .. for security reasons; apache needs an URL-path
RewriteRule ^([^.]+\.png)$ /fileGiver.php?file=$1&id=%1 [L]

Open in new window

0
 
LVL 1

Author Comment

by:Nargzul
ID: 24171967
restricting png? But as I've said It must work for many many differents types.

Images(jpg,png,gif,svg), xml, ...

I don't understand clearly the condition, the ^ signify that is the begining of the url? but "id=..." is never the begining of the url no?

for the rewrite rule I can use:

^([^.]+\.[a-z]+)$
0
 
LVL 27

Assisted Solution

by:caterham_www
caterham_www earned 2000 total points
ID: 24172185
> for the rewrite rule I can use:

Better than .*, yes, to reject e.g. some .htpasswd at this early point.

> ^ signify that is the begining of the url

Of the string tested in the condition, i.e., the query string, not the URL.
0
 
LVL 1

Author Closing Comment

by:Nargzul
ID: 31571481
Works fine!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question