Regla de expresiones regulares para que coincida con el% de la URL de inicio de sesión para la reescritura del mod apache

Hello my rewrite rule is failling sometimes because my urls have % signs in them.

For example this url:

http://www.chillisource.co.uk/product/Grocery/Dr.%20Burnoriums%20Psycho%20Juice/1/B005MSE5KG/Psycho_Juice_70%_Ghost_Pepper

This is my rewrite rule:

RewriteRule ^product/([a-zA-Z]+)/([\sa-zA-Z0-9\-\+\.]+)/([0-9]+)/([A-Z0-9]+)/([a-zA-Z0-9]+) /product?&cat=$1&q=$2&page=$3&prod=$4&prodName=$5

How can I modify the 5th rule ([a-zA-Z0-9]+) to not fail on when there is a % in the product name ?

Gracias de antemano.

preguntado el 08 de noviembre de 11 a las 18:11

I assume you've tried "([a-zA-Z0-9\%]+)"? -

@Truth You're right...I'd had the same thought, about 2 seconds after clicking the button. -

2 Respuestas

Perhaps, it's not %20, but space. That is, the URL passed to rewrite adter urldecoding. If not, then just add percent sign to the range. (if yes — space).

respondido 08 nov., 11:22

---- Forget this part, I misunderstood the question ----

From what I get from the mod_rewrite documentation (http://httpd.apache.org/docs/current/mod/mod_rewrite.html), you should not have to deal with hex encoded characters (I assume that from the following statement:

THE_REQUEST The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/1.1"). This does not include any additional headers sent by the browser. This value has not been unescaped (decoded), unlike most other variables below.

In fact, using mod_rewrite would be practically impossible since you'd have to deal with that POR TODOS LADOS, e.g., you can always write %41 instead of 'A'.

--- But the following still is true ---

But your rewrite rule can't work, at least not with the request URL you posted: The last part of the regex "([a-zA-Z0-9]+)" is FAR too strict. In this case, it fails for the following reasons:

  • It lacks a treatment of the percent sign, as in "70%"
  • You forgot to include the underscore "_"

Try adding at least these two characters ("[a-zA-Z0-9%_]+") and it should work.

respondido 08 nov., 11:22

("[a-zA-Z0-9%_]+") doesn't work either... :( how do I make my regex's less strict, is it possible to just let everthing through? - Ben Paton

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.