2
Well, I have a problem with the .htaccess e a URL amigável
, it works, but sometimes it stops and comes back to work. (Rewrite module is active, use PHP 7). And I have one more question, I have a briefcase at the root called view
, inside her I have a file called v_login.php
, how can I make the url stay localhost/projeto/login
? This would be passed by parameter like v_login for example and in index I would search that file by placing the path view/ and the extension .php, 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 solve.
.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';
}
?>