How to pass a second parameter using . htaccess to php code?

Asked

Viewed 188 times

0

I’m writing my api using . htaccess-friendly urls to do the redirects.

When I need to pass a second parameter, I’m having problems

My file . htaccesss is like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^mesas\/?([0-9]+)\/?(.+)\/?$ mesas.php?status=$1
RewriteRule ^statusmesa\/?([0-9]+)\/?(.+)\/?$ statusmesa.php?idmesa=$1&status=$2

When I use the call to statusmesa using statusmesa/2/3, it returns as first parameter the 2 and as a second 5.php/2/5

What’s wrong with my rule?

1 answer

0

If you just repeat the rule of the first parameter it does not work?

RewriteRule ^statusmesa\/?([0-9]+)\/?([0-9]+)\/?$ statusmesa.php?idmesa=$1&status=$2

Example

Example of friendly url: http://www.meudominio.com.br/artigos/26/12/2014

RewriteRule ^([a-z,0-9,A-Z,_-]+)\/([a-z,0-9,A-Z,_-]+)\/([a-z,0-9,A-Z,_-]+)\/?$ exemplo1.php?dia=$1&mes=$2&ano=$3

Rewriterule - Sets the beginning of a rewrite rule;

([a-z,0-9,A-Z,_-]+) - All characters (Numbers and Letters) + _ -;

/ - Bars;

/? - A bar or empty.

In this website there are some examples and more detailed explanations that can help you

  • It didn’t work. It would have something to do with the Rewriterule rule (.*)$1.php?

  • @Murilo Ai can no longer tell you, I never used it, when I did, I used the name of the direct file.

Browser other questions tagged

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