Problem with . htacess Url

Asked

Viewed 52 times

0

Good afternoon guys, I’m having a problem in my . htacess, I’m doing a test by xampp, only it returns me page not found or similar, I’ve done N form and nothing, man . htacess it takes the end of . php and adds do not know the problem is my index.php, I will send the codes.

.htacess

RewriteEngine On
RewriteBase /

# Remover extensão do arquivo (exemplo: /arquivo.php para /arquivo)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# Adicionar o barra (/) no final do endereço URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

# Redirecionar internamente as páginas sem extensão para o arquivo correspondente (crucial para o funcionamento da página)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

index php.

<?php
            $url = (isset($_GET['url'])) ? $_GET['url']:'home';
            $url = array_filter(explode('/',$url));

            $file = $url[0].'.php';

            if(is_file($file)){
                include $file;
            }else{
                include '404.php';
            }            
        ?>
  • Hello, explain better what you’re trying to do, please. If I understand correctly, you want to forward all requests to the 'index.php' page. That’s right?

  • the problem is that I don’t know if I did this part of the index.php , what I want is ex: http://meusite.com.br (home) quemsomos.php -> /quemsomos contato.php -> /contato

1 answer

0

I’ve had a similar problem and this . htacess helped me a lot:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.png -f 

This is not necessary the index.php you’ve built, just put your default home page for example:

index php.:

<!DOCTYPE html> <html> <head> <title>Olá!</title> </head> <body> </body> </html>
  • opa, muito obrigado, só uma Obs esse seu . htacess ele já oculta . php do final da pagina?

  • Yes, hide the. php

  • another question, in my case I don’t need to call this index.php, I can leave home as index.php?

  • Yes, you can let the home as index.php that you will read as the main page, you do not need the code you created, but if you want to go from /index to /home just use a redirect or header Location

Browser other questions tagged

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