User-friendly URL with HTACCESS

Asked

Viewed 655 times

1

I’m making my system that will use htaccess-friendly URL, only I’m having a question/problem. My HTACCESS is as follows:

RewriteEngine ON

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?page=$1

It works when I access something like www.meusite.com.br/registration only that I have another URL that I have to access as the URL above, only this way www.meusite.com.br/view/sheet/6

VIEW = view.php FICHE = category 6 = ID

I need to pass this data to the view.php file in the folder pages

  • http://blog.thiagobelem.net/aprendendo-urls-amigaveis-com-regras-complexas/

  • take a look at this link... the explanation is quite complete

1 answer

1

The ideal scenario is for you to focus routing on the application itself, making it more flexible and dynamic, while simplifying redirects on the webserver.

Anyway to except the rule that forwards all accesses to non-existent files and directories, you can add the line below before the last:

RewriteRule ^visualizar/ficha/([0-9]+)$ pages/visualizar.php?categoria=$1
  • in the place "plug/" I also have to send to the file visualize.php because it will be dynamic and not only plug. How would do this?

  • Regular expression is used in Rewriterule, so you can specify multiple rules, example: RewriteRule ^visualizar/(ficha|opcao2|opcao3)/([0-9]+)$ pages/visualizar.php?categoria=$1&id=$2 where in this case you would inform in category the options "plug", "option 2" and "option 3", or you can replace with "([a-z]+)" to allow any lowercase text.

  • I put what you sent and is running the last line only that would be Rewriterule (.*)$ index.php? page=$1 and does not execute the one you sent, and I put it first in htaccess

  • Since you do not use Rewritebase, add the "/"" character before "viewing": RewriteRule ^/visualizar/(ficha|opcao2|opcao3)/([0-9]+)$ pages/visualizar.php?categoria=$1&id=$2

  • is giving the same thing yet. Running the last command and not this one. I am using this way Rewriterule /visualize/([a-z]+)/([0-9]+)$ pages/visualize.php? p=$1&id=$2

  • And what URL you are accessing?

  • http://localhost:8080/FJU/view/chips/6

  • In this case if . htaccess is inside FJU, you can use RewriteBase /FJU/ and use the initial Rwriterule, with display... no initial bar

  • Remains the same :/

Show 4 more comments

Browser other questions tagged

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