[英].htaccess get variable through url rewrite not working
我的.htaccess
文件中有一个脚本,我试图在其中将 url 从localhost/testing/user/index?username=example
更改为localhost/testing/user/example
。
我这样做只是为了让我的网站看起来“更干净”,并且更容易浏览用户。
这是我当前的 htaccess 文件:
RewriteEngine On
RewriteRule ^user/([A-Za-z0-9-]+)$ user/index?username=$1;
RewriteRule ^user/$ user/index;
出于某种原因,这对我不起作用,并且总是抛出404或500错误。
这是我用来获取通过 URL 传递的用户名的 PHP 代码。
if(isset($_GET['username']) && empty($_GET['username'])){
header('location: ./');
}
if(empty($_GET['username']) && logged_in() == false){
header('location: ./');
} else if(empty($_GET['username']) && logged_in() == true || isset($_GET['username']) && $_GET['username'] === $username){
$pageDisp = 1;
} else if(!empty($_GET['username']) && $_GET['username'] !== $username){
$pageDisp = 2;
}
在 PHP 中,如果$_GET['username']
为空,它只会将用户设置为已登录的用户,但如果他们已登录,则会将其重定向到 404。
这是我的文件夹和脚本的布局:
.htaccess : /testing/user/
用户 index.php : /testing/user/
主 index.php : /testing/
所有这些文件都位于我的 XAMPP htdocs 文件夹中。
感谢所有帮助谢谢
这段代码对我有用
匹配/testing/user/*
之后的任何内容
访问
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^testing/users/([^/]*)$ /testing/users/?username=$1 [L]
/testing/users/
里面的 index.php (test)
<?php echo $_GET['username'] ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.