Generic Parameter Friendly URL . htaccess

Asked

Viewed 627 times

2

I’d like to ride a URL user-friendly with generic parameters, ie that receive any parameter in any quantity or file.

Today I rode the .htaccess so that the file name becomes the URL. File I am using:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*?)$ $1.php
    Options -Indexes

    ErrorDocument 404 /erro.php
</IfModule>

Example of URL who would like:

site.com.br/filename/parametro-01/parametro-02/parametro-03/...

In case anyone knows how to ride, it would be very helpful.

  • Moises, take a look at this answer and see if this is what you wish: http://answall.com/a/75970/8493

  • @Kaduamaral There is no direct form in the .htaccess? Need to treat in the PHP even?

  • Yes @Moisesgama, htaccess itself is not for programming, it’s just a configuration file. You need to handle in PHP, which I don’t see any downside.

1 answer

0

You can do it this way, so you create the post file and leave it as if it were an example category: www.site.com.br/post/first-materia/1 in this example you need to pass the post ID to list on the site with the GET method.

RewriteEngine On
RewriteBase /
#1
RewriteRule ^post\/([^\/]|.+[^\/]+)\/(\d+)\/?$ /posts.php?nome=$1&sid=$2
[QSA,L]
#0
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
  • Hello, in this example it will receive 2 parameters, if you want I will have to change the .htacess and put the third. That’s exactly what I don’t want. I want any files, receive any parameter in a friendly way. I’m sorry if I wasn’t clear on the question.

Browser other questions tagged

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