I have a friendly URL as follows:
www.dominio.com.br/cidade/sao-paulo
And here's my htaccess rewrite rule:
RewriteRule ^cidade/(.*)$ busca-cidade.php?cidade=$1
And the SQL query:
Select * from cidades where cidade = 'sao-paulo'
Is it possible to replace the hyphens with spaces using htaccess and rewrite rules? So the friendly URL will be mapped to:
www.dominio.com.br/busca-cidade.php?cidade=sao%20paulo
This finished my code, was great, would give to optimize.
####################################TESTE
RewriteRule ^teste?$ busca-cidade.php?locacao_venda=L
#(1) http://www.imobiliariaemaximovel.com.br/teste
#GET TIPO IMOVEL
RewriteRule ^(teste/[^\-]*)[\-]+(.*)([^\-]*)([^\-]*)$ $1\ $2 [DPI]
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^teste/([^\-]*)/([^\-]*)/([^\-]*)?$ /busca-cidade.php?locacao_venda=L&cidade=$1&tipo_mae=$2&tipo_imovel=$3 [L,QSA]
#(4) imobiliariaemaximovel.com.br/teste/Sorocaba/Apartamentos/Apto-Padrao
#GETREFERENCIA
RewriteRule ^(teste/[^\-]*)[\-]+(.*)([^\-]*)([^\-]*)([^\-]*)([^\-]*)$ $1\ $2 [DPI]
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^teste/([^\-]*)/([^\-]*)/([^\-]*)/([^\-]*)/([^\-]*)?$ /tudo-imovel.php?codigo=$5 [L,QSA]
#(6) imobiliariaemaximovel.com.br/teste/Sorocaba/Apartamentos/Apto-Padrao/Jardim-Pacaembu/16538
#GET BAIRRO
RewriteRule ^(teste/[^\-]*)[\-]+(.*)([^\-]*)([^\-]*)([^\-]*)$ $1\ $2 [DPI]
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^teste/([^\-]*)/([^\-]*)/([^\-]*)/([^\-]*)?$ /busca-cidade.php?locacao_venda=L&cidade=$1&tipo_mae=$2&tipo_imovel=$3&bairro=$4 [L,QSA]
#(5) imobiliariaemaximovel.com.br/teste/Sorocaba/Apartamentos/Apto-Padrao/Jardim-Pacaembu
#GET TIPO MAE
RewriteRule ^(teste/[^\-]*)[\-]+(.*)([^\-]*)$ $1\ $2 [DPI]
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^teste/([^\-]*)/([^\-]*)?$ /busca-cidade.php?locacao_venda=L&cidade=$1&tipo_mae=$2 [L,QSA]
#(3) imobiliariaemaximovel.com.br/teste/Sorocaba/Apartamentos
#GET CIDADE LOCAÇÃO
RewriteRule ^(teste/[^\-]*)[\-]+(.*)$ $1\ $2 [DPI]
RewriteCond %{REQUEST_URI} !\-
RewriteRule ^teste/([^\-]+)$ /busca-cidade.php?locacao_venda=L&cidade=$1 [L,QSA]
#(2) imobiliariaemaximovel.com.br/teste/Sorocaba
Semantic order, however, in my htaccess it is confusing, but works rsrs
#(1) /teste
#(2) /teste/Sorocaba
#(3) /teste/Sorocaba/Apartamentos
#(4) /teste/Sorocaba/Apartamentos/Apto-Padrao
#(5) /teste/Sorocaba/Apartamentos/Apto-Padrao/Jardim-Pacaembu
#(6) /teste/Sorocaba/Apartamentos/Apto-Padrao/Jardim-Pacaembu/16538