Frank Helligberger Frank Helligberger - 25 days ago 12
HTTP Question

HTTP Bad Request error because of a character

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?

Answer

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.

Comments