Multiple Rewrite Rules with . htaccess

Asked

Viewed 1,162 times

1

I have the following . htaccess currently:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

## Esconder .PHP
    # Redirecionamento externo de /dir/foo.php para /dir/foo
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
        RewriteRule ^ %1 [R=302,L]

    # Redirecionamento interno de /dir/foo para /dir/foo.php
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}.php -f
        RewriteRule ^(.*?)/?$ $1.php [L]


## Redirecionamento para o parametro P do GET na index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?p=$1 [NC,L,QSA]

# Esconder a palavra "index"
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index($|\ |\?)
    RewriteRule ^ /%1 [R=301,L]
</IfModule>

Now I have to pass a parameter to one of the pages that is already accessed by the rule of index.php?p=$1 that in this case exists and works in the URL:

www.site.com.br/portfolio?trabalho=14

Now I need to merge the rules to be able to access the above url from:

www.site.com.br/portfolio/14

Is it possible? Can you help me?

Grateful!

1 answer

0


You can add the code below just after the # Redirect block

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?p=$1&id=$2 [L]

So Voce will be taking the second parameter after the bar and php will receive in the get id variable ($_GET['id'])

Browser other questions tagged

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