【发布时间】:2010-12-04 01:42:35
【问题描述】:
我想要什么:
到 301 重定向 /file_new.pdf 到 /file new.pdf ( %20 之间的空格 文件和新)
我知道:
- 我可以依靠使用 mod_rewrite 的 RewriteRule 301,使用此线程中的解决方案:@mod_rewrite with spaces in the urls
- 我可以将文件重命名为不包含空格并将其替换为破折号/下划线
但是,我个人很好奇如何做到这一点。到目前为止,这是我所拥有的:
Redirect 301 /file_new.pdf http://sitename.com/file\ new.pdf
当我调用 configtest 时,conf 文件解析器抛出错误:
重定向需要两个或三个参数, 一个可选的状态,然后记录到 被重定向和目标网址
编辑: 显然 mod_rewrite 或 Redirect 301 方法对我有用,可能是因为无论出于何种原因,它们都没有应用,因为文件实际上存在于该位置。
<VirtualHost *:80>
DocumentRoot /www/sitename_com
ServerName site.local
Options -MultiViews
RewriteEngine on
Redirect 301 /pdf/file_new.pdf http://site.local/pdf/file%20new.pdf
RewriteRule ^/pdf/file_new.pdf http://site.local/pdf/file\ new.pdf
RewriteLog "/www/rewrite.log"
</VirtualHost>
在 rewrite.log 中,它尝试将模式与每个相应的 uri / http 请求进行匹配。我认为在它到达 mod_alias/mod_rewrite 的东西之前,有些东西正在控制。
总而言之,它直接转到浏览器中的 file_new.pdf 而不是 301。我很肯定 alias 和 rewrite 已启用。我的 apache 版本是 2.2。
【问题讨论】:
-
嗯。我突然想到我可能可以在那里硬编码 %20。
-
是的,就是这样。硬编码
%20。 -
如果你有 get 参数数组 site.local/?param[]=1¶m[]=2 不要忘记将 [] 编码为 %5B%5D -> site.local/?param%5B%5D=1¶m%5B%5D=2.
标签: apache mod-rewrite http-status-code-301 mod-alias