It may be that your 'problem' is more a design issue.
See that your permission array does not match, so you need to get the 1st bar that corresponds to a file that will scan bar by bar with a series of if's.
$permissao = array( 'home' , 'comer' , 'dormir' , '...' );
if(!isset($primeiraUrl) || $primeiraUrl == ''){
include("conteudos/home.php");
}elseif(isset($primeiraUrl) && in_array($primeiraUrl, $permissao)){
include("".$directorio."/".$primeiraUrl.".php");
}
This form is very flexible, the ideal is to create a config file that abstracts the routes and a file to validate.
If the URL is http://exemplo.pt/empresa-x
, then its $primeiraUrl
variable will have the company-x value, and this is outside its rules in the $permissao
array.
One solution that would solve your problem would be to treat the exception as an ad page. This way,% s of% URLs will be accepted and it will be up to the system to check if the ad was found or not and will continue to work for other URL's you have, type http://exemplo.pt/qualquer-nome-de-empresa
, http://exemplo.pt/comer/
.
solution
if( ! isset( $primeiraUrl ) || $primeiraUrl == '' ) {
include 'conteudos/home.php';
} elseif( in_array( $primeiraUrl , $permissao ) ) {
include "{$directorio}/{$primeiraUrl}.php";
} else {
// $primeiraUrl não está no array, posso SUPOR que seja um anuncio
// include no arquivo que carrega o anuncio
// include 'anuncio.php';
}
ad.php
Verifica no DB se '$primeiraUrl' corresponde a algum anúncio
caso contrário, você apresenta sua mensagem de erro.404
OBS , this solves the problem but is not ideal. I recommend looking for routes in PHP
Update
By doing .HTACCESS routing, you would have to define all possible routes, including order, as in the example below.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# http://exemplo.pt/comer/
RewriteRule ^comer\/$ index.php?controller=comer&option=index [QSA,L]
# http://exemplo.pt/comer/camarao/
RewriteRule ^comer\/([a-zA-Z-0-9-_]+)\/ index.php?controller=comer&option=tipo&tipo=$1 [QSA,L]
# http://exemplo.pt/restaurante-do-joao/
RewriteRule ^([a-zA-Z-0-9-_]+)\.html index.php?controller=anuncio&option=$1 [QSA,L]
The advantage will be that you will not need to make PHP combine the possible routes by combining input and output. You will receive via http://exemplo.pt/dormir/
the ready parameters.
Notice that I alluded to an MVC-based system. Not being your case, then GET
represents a physical file that will work with controller
. Everything will start with option
, so a shallow example would be:
For the input URL index.php
, you will have
$_GET['controller'] = 'anuncio'
$_GET['option'] = 'restaurante-do-joao'
In your index.php you do the correct checks - which I have omitted - and send the corresponding file to the controller:
//include anuncio.php
include $_GET['controller'] . 'php';
In the example case, ad.php will be loaded, and you will use http://exemplo.pt/comer/restaurante-do-joao/
to find the company name.