Well, I have a problem with .htaccess e a URL amigável
, it works, but sometimes it stops and it works again. (Rewrite module is active, use PHP 7). And I have one more question, I have a folder in the root called view
, inside it I have a file named v_login.php
, how can I make the url to be localhost/projeto/login
? This would be passed by parameter like v_login for example and in the index I would look for this file by putting the path view / and the .php extension , and would give a require_once in it?
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
index.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
echo 'Homepage';
?>
</body>
</html>
I managed to resolve.
.htaccess:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1
index.php
<?php
$home = 'view/home.php';
$url = (isset($_GET['url'])) ? $_GET['url'] : $home;
if ($url != $home) {
$dir = 'view/';
$url = array_filter(explode('/', $url));
$url = $dir. $url[0] . '.php';
}
// var_dump($url);
if (file_exists($url)) {
include_once $url;
} else {
include_once 'view/404.php';
}
?>