Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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 对于.htaccess,除了';之外,最适合匹配任何内容的正则表达式是什么';或'/';_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 对于.htaccess,除了';之外,最适合匹配任何内容的正则表达式是什么';或'/';

Php 对于.htaccess,除了';之外,最适合匹配任何内容的正则表达式是什么';或'/';,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我在.htaccess文件中编写了一段代码,用于搜索引擎友好的URL: RewriteRule ^games/(.*\S)$ helper/Games.php?p=$1 [L] 如您所见,games/之后的任何内容都会重写为helper/games.php?p= 但是我不想要$\u GET['p']包含?或/的开关 例如,根据我的规则,下面的URL应该而不是: example.com/games/Test?Test example.com/games/Test/Test 请引导我找到正确的正

我在.htaccess文件中编写了一段代码,用于搜索引擎友好的URL:

RewriteRule ^games/(.*\S)$ helper/Games.php?p=$1 [L]
如您所见,
games/
之后的任何内容都会重写为
helper/games.php?p=

但是我不想要
$\u GET['p']
包含
/
的开关

例如,根据我的规则,下面的URL应该而不是

example.com/games/Test?Test
example.com/games/Test/Test
请引导我找到正确的正则表达式。
谢谢。

您只需要对不需要的值集求反,而不是使用通配符
。因此:

RewriteRule^games/([^/]*[^\s/])$helper/games.php?p=$1[L]

由于查询字符串不是匹配的一部分,因此首先需要:

RewriteCond%{QUERY\u STRING}^$

在重写url之前,您需要匹配空查询字符串:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^test/([^/]+)$ helper/Gampes.php?p=$1 [L]

Tnx。这对刀砍很有效。但仍然重写
example.com/games/Test?Test
:(我不记得Apache的正则表达式解析器是如何工作的,但我希望这一切都会好起来!无论如何,试着在问号前加一个反斜杠“\”。。这不是RewriteRule模式中匹配的一部分。除非使用RewriteCond,否则您没有选择删除它。如何?您知道吗?@starkeenGood idea。谢谢@starkeen