Problem with search and friendly url

3

Good evening,

I have a search that is working fine, I'm only now having a problem when someone writes a word with an accent or two words separated by space, I break the url.

Would you like to know how I can resolve this situation?

Code

 <form method="post" id="form" action="">
          <div style="margin-left:150px;">
              <div style="float:left; width:500px;"><input style="height: 38px;" id="valor_pesquisa" name="valor_pesquisa" type="text" placeholder="Restaurantes, bares, hotéis..." /></div>
              <div style="float:left; margin-left:5px;"><input type="submit" value="Pesquisar" /></div>
          </div> 
        </form>
        <script>
          $(function() {
              $("#form").submit(function(e) {
                  if($('#valor_pesquisa').val() === ''){
                      $("#form").attr("action", "http://sabeonde.pt/locais/pesquisa/todos");
                  }else{
                    var valor_pesquisa = $("#valor_pesquisa").val();
                    $("#form").attr("action", "http://sabeonde.pt/locais/pesquisa/"+valor_pesquisa);
                  }
              });
          });
        </script>

.htaccess

# Rota Pesquisa
RewriteRule ^locais/pesquisa/([a-zA-Z-0-9-_]+)$  index.php?controller=pesquisa&option=pesquisa&pesquisa=$1

Current

RewriteRule ^locais/pesquisa/([\p{L}\p{N}\s_-]+)$  index.php?controller=pesquisa&option=pesquisa&pesquisa=$1
    
asked by anonymous 21.03.2015 / 23:39

3 answers

1

Well I ended up solving my problem with the following regex so that you need it.

RewriteRule ^locais/pesquisa/([A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÊÍÏÓÒÖÚÇÑ\s_-]+$)$  index.php?controller=pesquisa&option=pesquisa&pesquisa=$1

Of course with help of all the answers here given thanks to all

    
22.03.2015 / 03:41
0

I believe you can include other ranges in RegEx to allow characters with accents, type [À-üa-zA-Z0-9 _-]+

    
22.03.2015 / 01:13
-1

var valor_pesquisa = window.encodeURIComponent($("#valor_pesquisa").val());

    
21.03.2015 / 23:42