Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/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
Apache 在URL中使用空格重写mod__Apache_Url_Mod Rewrite - Fatal编程技术网

Apache 在URL中使用空格重写mod_

Apache 在URL中使用空格重写mod_,apache,url,mod-rewrite,Apache,Url,Mod Rewrite,我需要设置一些重写规则来重定向包含空格的URL。我试过这个: RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L] 。。。但它不起作用。放入空间而不是%20会导致500内部服务器错误。如何添加空间?啊,我找到了一个解决方案:使用正则表达式样式显示空间: RewriteRule ^article/with\sspaces.html$ ... 不过,我怀疑这也会匹配所有其他空白字符,如制表符

我需要设置一些重写规则来重定向包含空格的URL。我试过这个:

RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L]

。。。但它不起作用。放入空间而不是%20会导致500内部服务器错误。如何添加空间?

啊,我找到了一个解决方案:使用正则表达式样式显示空间:

RewriteRule ^article/with\sspaces.html$ ...

不过,我怀疑这也会匹配所有其他空白字符,如制表符等,但我认为这不会有多大问题。

尝试在空格前放置\以避开它

RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]

你可以用一只手逃离这个空间\


第一个选项替换一个空格,而第二个选项替换url中硬编码的%20。

如果您想避免转义每个空格的复杂性,例如,如果您计划自动生成此文件,只需使用引号:

RewriteRule "^article/with spaces.html$" /article/without_spaces.html [R=301,L]
此外,这些引号可用于封装任何一个预期参数:

RewriteRule "^article/with spaces.html$" "/article/without_spaces.html" [R=301,L]

干杯我想应该是这么简单的事情。这应该得到最高的票数。但是,唉!时机取决于投票,这是最好的答案
RewriteRule "^article/with spaces.html$" "/article/without_spaces.html" [R=301,L]