我需要设置一些RewriteRules来重定向一个URL,该URL中有一个空格。我试过这个:带有空格的mod_rewrite
RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L]
...但它不起作用。放入空格而不是%20会导致500内部服务器错误。我如何添加空间?
我需要设置一些RewriteRules来重定向一个URL,该URL中有一个空格。我试过这个:带有空格的mod_rewrite
RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L]
...但它不起作用。放入空格而不是%20会导致500内部服务器错误。我如何添加空间?
尝试在你的空间前放一个\来逃避它。
RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
啊,我已经找到了解决办法:使用正则表达式的风格展现出空间:
RewriteRule ^article/with\sspaces.html$ ...
虽然,我怀疑这会匹配所有其它空白字符太(标签等),但我认为这不会有什么问题。
你可以只用一个\
RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L]
RewriteRule ^article/with[\ |%2520]spaces.html$ /article/without_spaces.html [R=301,L]
躲避空间中的第一选项替换空间,而第二替换URL中的硬编码的20%。
这应该得到最高票数。可惜!时间取决于选票。 – 2016-04-01 08:46: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]
干杯!我应该想到它会是这样简单的事情。 – nickf 2009-01-04 10:58:59