Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在url中显示用户名,而不是使用.htaccess显示id_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 在url中显示用户名,而不是使用.htaccess显示id

Php 在url中显示用户名,而不是使用.htaccess显示id,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我已经找过这个,这个还有其他的。但这对我来说仍然不起作用。当用户查看其个人资料时,我当前的url如下http://localhost/sn/profile.php?id=1现在我想要的url是这样的http://localhost/sn/myusername我知道这可能是重复的,但到目前为止,任何答案都不适用于我:(有什么需要帮忙的吗?先谢谢你 这是我在我的.htaccess RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUES

我已经找过这个,这个还有其他的。但这对我来说仍然不起作用。当用户查看其个人资料时,我当前的
url
如下
http://localhost/sn/profile.php?id=1
现在我想要的
url
是这样的
http://localhost/sn/myusername
我知道这可能是重复的,但到目前为止,任何答案都不适用于我:(有什么需要帮忙的吗?先谢谢你

这是我在我的
.htaccess

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)/$ http://localhost/sn/profile.php?id=$1

您的htaccess代码应如下所示:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?id=$1 [L]

请注意,您必须更改
profile.php
中的逻辑,才能通过用户名(不再通过ID)获取用户

您的htaccess在哪里?在您的
sn
目录或文档根目录中?它与我的
index.php
profile.php一起位于
sn
文件夹中。先生,您这样说是什么意思?例如:您想访问
http://localhost/sn/Pengun
内部重定向到to
profile.php?id=Pengun
。以前,您的php页面接收id,但现在是用户名