下面是我的.htaccess:
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!= /的favicon.ico
重写规则^(。*)$ profile.php?用户= $ 1 [L,QSA]
< / IfModule>
下面是profile.php:
如果(使用isset($ _ GET ['用户'])及和放大器; strlen的($ _ GET ['用户'])大于0){
$ userreal = $ _GET ['用户'];
$语句= $ mysqli-> prepare(选择用户名从用户其中username =?);
$ stmt-> bind_param('S',$ userreal);
$ stmt->执行();
$ stmt-> store_result();
如果($ stmt-> NUM_ROWS == 1){
$ USER = $ _GET ['用户'];
}
其他 {
$ US = $ _SESSION [用户名];
标题(位置:配置文件/美元);
出口();
}
$ stmt->关闭();
}
其他 {
$ US = $ _SESSION [用户名];
标题(位置:配置文件/美元);
出口();
}
这是我的重定向的一部分(认为它可能是有帮助的)。
但它重定向我:
http://localhost/PHP/Projects/HassanTech/pages/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/Hassan当我尝试访问
的http://本地主机/ PHP /项目/ HassanTech /页/简介
我想我的链接:
的http://本地主机/ PHP /项目/ HassanTech /页/配置文件的用户=哈桑
到
的http://本地主机/ PHP /项目/ HassanTech /页/型材/哈桑
我的.htaccess文件是在网页文件夹和profile.php在网页文件夹中。希望你能帮助我。
解决方案更改你的头重定向时使用 ./
键,你会留在同一个目录从而解决您的问题
标题(位置:./美元);
Here is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ profile.php?user=$1 [L,QSA]
</IfModule>
here is profile.php:
if(isset($_GET['user']) && strlen($_GET['user'])>0) {
$userreal = $_GET['user'];
$stmt = $mysqli->prepare("SELECT username FROM users WHERE username=?");
$stmt->bind_param('s', $userreal);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 1) {
$user = $_GET['user'];
}
else {
$us = $_SESSION['username'];
header("Location: profile/" . $us);
exit();
}
$stmt->close();
}
else {
$us = $_SESSION['username'];
header("Location: profile/" . $us);
exit();
}
This is my redirecting part (thought it might be helpful).
but it redirects me to:
http://localhost/PHP/Projects/HassanTech/pages/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/Hassan
when I try to access
http://localhost/PHP/Projects/HassanTech/pages/profile
I want my links:
http://localhost/PHP/Projects/HassanTech/pages/profile?user=Hassan
to
http://localhost/PHP/Projects/HassanTech/pages/profile/Hassan
My .htaccess file is in the pages folder and the profile.php is in the pages folder. Hope you can help me.
解决方案Change your header redirect to use ./
and you will stay in the same directory thus resolving your problem:
header("Location: ./" . $us);
上一篇:为什么我不能在我的重写规则斜线?我的、我不、斜线、能在
下一篇:隐藏在父文件夹的所有childfolders上市,但显示childfolder内容文件夹、内容、childfolders、childfolder