Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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_Url_Mod Rewrite_Url Rewriting - Fatal编程技术网

Php URL重写短语问题

Php URL重写短语问题,php,apache,url,mod-rewrite,url-rewriting,Php,Apache,Url,Mod Rewrite,Url Rewriting,我有一个我想重写的URLmysite.com/accounts?id=test应该指向mysite.com/accounts.php?id=test。我已经检查了我的mod_rewrite,它可以正常工作,因为其他页面可以正确编写。我目前正在尝试: RewriteRule^accounts?([.]+)$accounts.php?$1[NC,L] 这似乎不起作用。是因为正则表达式中的问号吗?我试图用\来逃避它,但仍然不起作用 任何帮助都将不胜感激。首先,我认为([.]+)与(.*)相同 其次,R

我有一个我想重写的URL
mysite.com/accounts?id=test
应该指向
mysite.com/accounts.php?id=test
。我已经检查了我的
mod_rewrite
,它可以正常工作,因为其他页面可以正确编写。我目前正在尝试:

RewriteRule^accounts?([.]+)$accounts.php?$1[NC,L]

这似乎不起作用。是因为正则表达式中的问号吗?我试图用\来逃避它,但仍然不起作用

任何帮助都将不胜感激。

首先,我认为
([.]+)
(.*)
相同

其次,RewriteRule已经从URL中删除了您的查询字符串。
您可以使用
%{QUERY\u STRING}
访问它

所以你的代码是

RewriteRule ^accounts?(.*)$ accounts.php?%{QUERY_STRING} [NC,L]
您可以使用以下内容创建accounts.php进行测试:

<?php
echo "<pre>";
print_r($_SERVER);
exit();
// rest of your code
?>


然后检查您的
[QUERY\u STRING]

为什么不将问号全部丢失,并将id设置为子文件夹或页面。然后规则会是这样的:RewriteRule^accounts/([.]+).html$accounts.php?id=$1可能我错了,但是为什么[]之间的点?这与
(.*)
不一样吗?我认为
RewriteRule^accounts?(.*)$accounts.php?$1[NC,L]
应该行得通。@Rik,这种方法行得通。。现在至少找到了account.php文件。(它曾经给出404)。现在在我写的第一行die($_GET['id'])只是为了测试,它返回空白。有什么想法吗?@l3utterfly我用这个解决方案创造了一个答案。