skip to Main Content

I am using .htaccess to convert a link with the following parameters…:

www.domain.com/ offer.php?id=1000&title=All shirts are with a discount of 20%

to

www.domain.com/ offer/1000/All shirts are with a discount of 20%

Now when I try opening the link I get displayed a server side error:

Bad Request
Your browser sent a request that this server could not understand.

In my code the title value does not play any role, but I need it for SEO reasons. So when I remove the “%” character from the link the page opens without a problem.

So how can I fix this issue so my link will open despite the percentage character in the HTTP request?

2

Answers


  1. The percent sign (%) is used to encode special characters in a url string. Hence, it has special meaning, and must be passed as an encoded character, which is %25.

    Since you pass an indication of a special character and do not send anything else, you get the error.

    Login or Signup to reply.
  2. As stated by Nordenheim the problem is using special characters in your title attribute.

    Using PHP you may well want to use urlencode() on your title attribute on the sending link,

    So:

    <?php
    
    $title = "All shirts are with a discount of 20%";
    $link = urlencode($title);
    
    ?>
    <a href='http://www.domain.com/offer.php?id=1000&title=<?php print $link;?>'>Click here</a>
    

    This will turn All shirts are with a discount of 20% into the URL safe string All+shirts+are+with+a+discount+of+20%25 and will resolve the error you are getting from your .htaccess mod_rewrite.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search