.htaccess to URL friendly

Asked

Viewed 6,399 times

0

How do I make rules Mod_Rewrite (htaccess) for my pages? I’m not used to .htaccess

Rules I would like:

www.exemplo.com/index.php for www.exemplo.com

www.exemplo.com/perfil.php for www.exemplo.com/perfil

www.exemplo.com/perfil.php?p=fulano-da-silva for www.exemplo.com/perfil/fulano-da-silva

www.exemplo.com/video.php?p=fulano-da-silva&m=nome-do-video for www.exempli.com/perfil/fulano-da-silva/nome-do-video

Code:

.htaccess

RewriteEngine On
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pag=$1

url.php

<?php
$atual = (isset($_GET['isw'])) ? $_GET['isw'] : 'home';
 $pasta = 'paginas';
if (substr_count($atual, '/') > 0) {
    $atual = explode('/', $atual);
    $pagina = (file_exists("{$pasta}/" . $atual[0] . '.php')) ? $atual[0] : 'erro';
    $id = $atual[1];
    $busca = @$atual[2];    

} else {    
    $pagina = (file_exists("{$pasta}/" . $atual . '.php')) ? $atual : 'erro';
    $id = 0;
    $frame=0;
}?>

index.php

<?php require_once('url.php') ?>
<?php include $pasta.'/'.$pagina.'.php'; ?>

Someone could shed a light?

  • 4

    Tremendous injustice here.. They edited my topic so many times it doesn’t even look like what I wrote anymore. The topic that linked to mine does not have the same characteristics, the guy formulated the question and only put the . htaccess, I would like to know how you could select which level by PHP.. This fact that anyone can edit what you write, sometimes ends up hurting someone who has a fair question. I, for example, could not do what I was looking for with the tips given in the other topic, until I got something, but nothing as I needed. The issues misread my topic.

1 answer

3


  • 2

    Thanks for the help. It was vague and unusual, but it was the only one who minimally tried to help.

Browser other questions tagged

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