9
I have the following php code to make the urls of my site friendly:
<?php
$atual = (isset($_GET['pg'])) ? $_GET['pg'] : 'home';
$permissao = array('home', 'contato', 'sobre', 'politica');
$pasta = 'arquivos';
if (substr_count($atual, '/') > 0){
$atual = explode('/', $atual);
$pagina = (file_exists("{$pasta}/".$atual[0].'.php') && in_array($atual[0], $permissao)) ? $atual[0] : 'erro';
} else {
$pagina = (file_exists("{$pasta}/".$atual.'.php') && in_array($atual, $permissao)) ? $atual : 'erro';
}
?>
My . htaccess is like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pg=$1 [L]
For static pages it works perfectly. The problem now is to adapt this code to dynamic pages.
On my website I will need a category.php page and company.php that will receive the 'Slug' value from my database.
Urls would look that way:
site.com.br/category.php? Slug=category-name
site.com.br/company.php? Slug=company name
How to turn these urls into:
site.com.br/category name
site.com.br/company/company name
How I should make the sql call on these pages to display the values of the database?
Can someone please help me?
Your question is about SQL or how should the
.htaccess
?– André Ribeiro
I need to know what the sql call would look like on the category.php and company.php pages. And in case this modification changes something in htaccess I needed to know how the new file would look.
– Junior
the way you’re doing, you’re letting PHP do Apache’s work, I suggest you read Learning Friendly Urls with Complex Rules
– RodrigoBorth
In the
.htaccess
writes a new expression for url, and sets the parameters in the category.php and enterprise.php– Edilson
Friendly URL’s: no headaches
– Edilson