Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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_Php_Apache_.htaccess - Fatal编程技术网

Php 使用查询字符串为用户页面使用干净的URL

Php 使用查询字符串为用户页面使用干净的URL,php,apache,.htaccess,Php,Apache,.htaccess,我已经为此奋斗了几个小时,试图让它做我想做的事情 我的根目录中有一个.htaccess文件,用于清除URL,其内容如下: #turn on url rewriting RewriteEngine on #remove the need for .php extention RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^.]+)$ $1.php [NC,L] 然后有一个目录/hnid,其中有一个user.php文件,它接受一个id为的g

我已经为此奋斗了几个小时,试图让它做我想做的事情

我的根目录中有一个.htaccess文件,用于清除URL,其内容如下:

#turn on url rewriting
RewriteEngine on

#remove the need for .php extention
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.php [NC,L]
然后有一个目录
/hnid
,其中有一个user.php文件,它接受一个id为的get请求。我在
/hnid
文件夹中也有一个.htaccess文件:

RewriteEngine on
RewriteRule ^user/([^/\.]+)/?$ user?id=$1 [L]
我的问题在于结果。我希望能够访问
/hnid/user/1a
以访问第27个用户(是的,我在文件中有转换id的处理)

user/1a给出404,user?id=1a给出404,user.php?id=1a工作正常,user.php/11返回以下消息:

Notice: Undefined index: id in /var/www/html/hnid/user.php on line 3

我不知道该怎么办,但我希望你们这些优秀的人能启发我。谢谢。

你能更新php文件吗?注意:第3行的/var/www/html/hnid/user.php中未定义的索引:id来自php警告,而不是apache。你尝试过:
重写规则^user/([^/\.]+)/?$user.php?id=$1[L]
。看起来你在这条规则中错过了
.php
,也许我应该停止编程。。。这是我第一次尝试的,但由于某些原因它不起作用,现在它是。今天科技已经两次这样对我了。坦克@Kyle@Bartha没问题:)把我的评论投赞成票就行了。apache可能有一些缓存,您也应该看看