.htaccess redirige la URL normal a la cadena de consulta
Frecuentes
Visto 911 veces
1
I have a url of the form:
www.example.com/r/abc/1234
that I want to rewrite to:
www.example.com/r.php?deb=abc&id=1234
And another url:
www.example.com/r/12bcd-qsqs-343-wdwd/1234
which should be rewritten to:
www.example.com/r.php?abc_id=12bcd-qsqs-343-wdwd&id=1234
Both of these rule should be handled by .htaccess. Any suggestions?
2 Respuestas
1
Both the URIs that you want to redirect look similar except that 2nd one has hyphens -
in first query parameter.
Habilite mod_rewrite y .htaccess a través de httpd.conf
y luego poner este código en su .htaccess
bajo DOCUMENT_ROOT
directorio:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^r/([^-]+)/(.+)/?$ r.php?deb=$1&id=$2 [L,QSA]
RewriteRule ^r/([a-z0-9-]+)/(.+)/?$ r.php?abc_id=$1&id=$2 [L,QSA,NC]
Respondido 28 ago 12, 09:08
Thanks for the help with little changes I have made it work, But now the problem is its working on my localhost but when I transferred it on the server were I am running virtualhost Its not working can you help ? - prathamesh mhatre
On the server make sure .htaccess is enabled and then if .htaccess is correctly paced in DOCUMENT_ROOT directory. If everything is right then add R
flag in above 2 RewriteRule lines to see what is the final URI on server. - anubhava
Thanks a lot :) Is there some how I can keep contact with you any social site or anything ? - prathamesh mhatre
You're welcome. Here is LinkedIn Contact: linkedin.com/in/anubhavasrivastava - anubhava
1
Prueba algo como:
RewriteRule (.*)/(.*)/(.*)$ path_to_php_files/$1.php?deb=$2&id=$3 [QSA,L,NC]
Unfortunately with this rule, you would have the first $_GET parameter always deb and I hope you have the DirectoryIndex set up corectly. I do not think that for
www.example.com/r/abc/1234
www.example.com/r/12bcd-qsqs-343-wdwd/1234
you can delivrer the abc and 12bcd-qsqs-343-wdwd to 2 different $_GET parameters if you have dynamic links.
Respondido 28 ago 12, 09:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php .htaccess url url-rewriting rewrite or haz tu propia pregunta.
Pass all into a script of your own and than inside that PHP script process the URI as one parameter. That is much more less specific to the webserver you are running on and more flexible. This normally only needs a single or very few rules. Compare: Reglas de reescritura de Symfony2 .htaccess app.php - hakre