How do I change the order of the URL Friendly parameters in htaccess?

Asked

Viewed 49 times

1

My URL friendlyl is like this: guaraparivirtual.com.br/news-Gadfly/Moqueca-capixaba-agua-na-boca/9/

I would like there to be an exchange of the order of place of the parameters from the last to the penultimate.

Thus: guaraparivirtual.com.br/noticias-Guarapari/9/moqueca-capixaba-agua-na-boca/

I did everything but without success.

Follows my code from .htaccess

URL

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteRule ^noticias-guarapari/([a-z0-9-]+)/([a-z0-9-]+)/?$ /noticias-guarapari.php?idnoticia=$2&nome=$1 [NC]
</IfModule>

I know it seems obvious, but I changed the order to:

 RewriteRule ^noticias-guarapari/([a-z0-9-]+)/([a-z0-9-]+)/?$ /noticias-guarapari.php?nome=$1&idnoticia=$2 [NC]

And I called the url: guaraparivirtual.com.br/noticias-Guarapari/9/moqueca-capixaba-agua-na-boca/

mysql content does not load when this last change I made is made, only the first one that works perfectly.

1 answer

1


Let’s understand the order of the parameters.

Before it was like this:

guaraparivirtual.com.br/noticias-Guarapari/moqueca-capixaba-agua-na-boca/9/

Having in order:

  1. moqueca-capixaba-agua-na-boca
  2. 9

Now you want it to stay that way:

guaraparivirtual.com.br/noticias-Guarapari/9/moqueca-capixaba-agua-na-boca/

Having in order:

  1. 9
  2. moqueca-capixaba-agua-na-boca

So it’s simple, just change:

name=$1 for name=$2

idnoticia=$2 for idnoticia=$1

Thus remaining:

                              # $1           $2
RewriteRule ^noticias-guarapari/([a-z0-9-]+)/([a-z0-9-]+)/?$ /noticias-guarapari.php?nome=$2&idnoticia=$1 [NC]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.