Problem with a Url Rewriting

Posted on 2009-04-17
Last Modified: 2012-05-06

I've a little problem,

I've URL like

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

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?
Question by:Nargzul
    LVL 27

    Accepted Solution

    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

    LVL 1

    Author Comment

    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:

    LVL 27

    Assisted Solution

    > 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.
    LVL 1

    Author Closing Comment

    Works fine!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now