Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
.htaccess HTC跟踪斜杠问题_.htaccess_Slash_Trailing - Fatal编程技术网

.htaccess HTC跟踪斜杠问题

.htaccess HTC跟踪斜杠问题,.htaccess,slash,trailing,.htaccess,Slash,Trailing,网址: 有人能解释为什么第二个条件后面有斜杠吗 另外,如何允许百分比登录url重写 上述规则不起作用。有人能纠正这一点,使其允许a-Z、0-9、点、连字符和百分号吗 谢谢 您将获得第二条重写规则的/,因为*是贪婪的。也就是说,它贪婪地捕获尾部斜杠,因为您已将其标记为可选的/?。最好针对您的模式(如第一个重写规则),以避免这种情况 您匹配的模式可以接受任何内容。请记住,它必须是一个有效的URL。问题是你忘记了量词。因此,您只匹配分组中的一个字符 添加+ RewriteRule ^url/of/

网址:

有人能解释为什么第二个条件后面有斜杠吗


另外,如何允许百分比登录url重写

上述规则不起作用。有人能纠正这一点,使其允许a-Z、0-9、点、连字符和百分号吗


谢谢

您将获得第二条
重写规则的
/
,因为
*
是贪婪的。也就是说,它贪婪地捕获尾部斜杠,因为您已将其标记为可选的
/?
。最好针对您的模式(如第一个
重写规则
),以避免这种情况

您匹配的模式可以接受任何内容。请记住,它必须是一个有效的URL。问题是你忘记了量词。因此,您只匹配分组中的一个字符

添加
+

RewriteRule ^url/of/the/keyword/([0-9a-zA-Z\-.%]+)/?$ ?keyword=$1 [L]

谢谢,杰森,我得到了第一个。第二个是打字错误,我忘了加号。但即使是加号,它也不起作用。结果是404。
// php  
echo $_GET['keyword'];    
// outputs **whatever** (OK)
RewriteRule ^url/of/the/keyword/(.*)/?$ ?keyword=$1 [L]  
// php  
echo $_GET['keyword'];  
// outputs **whatever/** (with a trailing slash, which is not expected)
RewriteRule ^url/of/the/keyword/([0-9a-zA-Z-.%])/?$ ?keyword=$1 [L]
RewriteRule ^url/of/the/keyword/([0-9a-zA-Z\-.%]+)/?$ ?keyword=$1 [L]