从
重写网址的最佳方法是什么?https://www.example.com/user/?user=MaxMustermann
到
https://www.example.com/MaxMustermann
我已经在带有RewriteRule的.htaccess-File中尝试过了,但如果我打开URL exmaple.com/login.php,我会收到消息" User not found",是否正确。我该如何解决这个问题?
答案 0 :(得分:0)
创建新的网站根.htaccess
,并输入以下代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(user)/([\w-]+)/?$ $1/?user=$2 [L,NC,QSA]
答案 1 :(得分:0)
我在名为user的文件夹中有这样的index.php:
<?php
$userid = 10;
if($userUrl = "gadiradufasha") {
include("../profile.php");
}
?>
然后我有:向后文件夹w / c中的profile.php,我打过一次电话!
<?php
session_start();
include ('query.php');
$object = new Query;
if(!isset($_SESSION['UserId'])) {
header("Location:../../");
}
$user= $userUrl;
if($user!=$_SESSION['User']) {
//$prostmt = $object->getUserDetails($userUrl);
$prostmt = $object->getUserDetailsByUsername($userUrl);
$profrow = $prostmt->fetch(PDO::FETCH_ASSOC);
?>