I have this website www.amse.com.br
For some reason, every link on the website is not working, and I know where the problem is, but don't know why.
The index.php script handles the false URLs and brings information to the web page from the data base:
<?php
require_once("api/connector.class.inc");
$url_cod = (isset($_REQUEST['cod'])) ? $_REQUEST['cod'] : '';
$url_nm_secao = explode('/', $url_cod);
$url_id = Connector::getAllName("tab_url", "id_tabela", "nm_url='" . $url_nm_secao[count($url_nm_secao)-1] . "'");
$url_tabela = Connector::getAllName("tab_url", "nm_tabela", "nm_url='" . $url_nm_secao[count($url_nm_secao)-1] . "'");
if($url_tabela == "tab_produto"){
$_REQUEST["codigo"] = $url_id;
include_once "detalhe-produto.php";
}else if($url_tabela == "tab_subcategoria"){
$_REQUEST["subcategoria"] = $url_id;
include_once "lista-produto.php";
}else if($url_tabela == "tab_categoria"){
$_REQUEST["categoria"] = $url_id;
include_once "lista-produto.php";
}else if($url_tabela == "tab_grupo"){
$_REQUEST["grupo"] = $url_id;
include_once "lista-produto.php";
}else if($url_tabela == "tab_conteudo"){
$_REQUEST["codigo"] = $url_id;
include_once "detalhe.php";
}else{
if(isset($url_nm_secao[0]) && $url_nm_secao[0] == '' || $url_nm_secao[0] == 'index.php'){
include_once "home.php";
}elseif($url_nm_secao[0] != ''){
$paginas = array('contato', 'carrinho', 'cadastro', 'pagamento', 'logout', 'salvar-pedido', 'endereco-de-entrega', 'retorno', 'obrigado', 'meus-pedidos', 'salvar-orcamento');
if(isset($url_nm_secao[0]) && in_array($url_nm_secao[0], $paginas)){
include_once $url_nm_secao[0].".php";
}else if($url_nm_secao[0] == "finalizar-compra"){
$_REQUEST["compra"] = 1;
include_once "cadastro.php";
}
else if($url_nm_secao[0] == "busca"){
include_once "lista-produto.php";
}
else if($url_nm_secao[0] == "locacao"){
include_once "lista-locacao.php";
}
}else{
include_once "home.php";
}
} ?>
For example, www.amse.com.br/contato
should bring up this page www.amse.com.br/contato.php
This should happen with every link on the website, but i'm getting 404
.
If you need any more information,
please leave on the comments!
Not sure if this will help but I cleaned it up some for you this was what I was saying with using a switch
switch($url_tabela){
case "tab_produto":
$_REQUEST["codigo"] = $url_id;
include_once "detalhe-produto.php";
break;
case "tab_subcategoria":
$_REQUEST["subcategoria"] = $url_id;
include_once "lista-produto.php";
break;
case "tab_categoria":
$_REQUEST["categoria"] = $url_id;
include_once "lista-produto.php";
break;
case "tab_grupo":
$_REQUEST["grupo"] = $url_id;
include_once "lista-produto.php";
break;
case "tab_conteudo":
$_REQUEST["codigo"] = $url_id;
include_once "detalhe.php";
break;
default:
if( !isset( $url_nm_secao[0] ) ){
$url_nm_secao[0] = '';
}
switch ( $url_nm_secao[0] ){
case "finalizar-compra":
$_REQUEST["compra"] = 1;
include_once "cadastro.php";
break;
case "busca":
include_once "lista-produto.php";
break;
case "locacao":
include_once "lista-locacao.php";
break;
default:
case 'index.php':
include_once "home.php";
break;
}
break;
}
As you can see it's much easier to read, I haven't tested this but it should be fairly close to what you have.
Php documentation for Switch Case
Your web server (Apache, etc) may not be configured to handle this type of clean URL.
By default a web server will look for a file with a matching name underneath its DocumentRoot, however your file is named contato.php
, not contato
. This means Apache is potentially looking for a file named contato
and not finding it, thus returning an HTTP 404 response.
If you are using Apache, a rewrite rule like this may be what you need
RewriteRule ^/([a-zA-Z0-9]+)([/a-zA-Z0-9]*)?$ /index.php?cod=$1$2&%{QUERY_STRING} [L]
This will take everything after the initial /
in the URL and pass it to your program in the cod
variable, making it available in $_REQUESt['cod']
above. With this I imagine your index.php will work as expected.