如何在 .htaccess 中以 %20 为目标文件?

发布于 2024-09-24 06:27:11 字数 265 浏览 2 评论 0原文

这是我的 .htaccess:

...
rewriterule file%20name.htm http://mysite.com/new_name.htm#anchor [r=301,nc,ne]
...

它没有重定向,我相信这是因为它没有针对名称中带有 %20 的文件。至于标志,我使用 ne 不重写重定向的 #anchor 部分。

另外,标志“nu”破坏了我的文件,并且出现内部服务器 500 错误。

感谢您。

Here is my .htaccess:

...
rewriterule file%20name.htm http://mysite.com/new_name.htm#anchor [r=301,nc,ne]
...

It's not redirected, and I believe this is because it's not targeting the file with the %20 in the name. As for the flags, I used ne to not rewrite the #anchor portion of the redirect.

Also, the flag "nu" breaks my file and I get internal server 500 error.

Thanks you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽梦紫曦~ 2024-10-01 06:27:11

当调用 mod_rewrite 时,该路径已经作为 Apache 请求处理的一部分进行了解码。因此,如果您想检查空格,可以按字面意思进行操作:

RewriteRule file\ name\.html http://example.com/new_name.htm#anchor [R=301,NC,NE,L]

NU 标志不存在,这就是为什么当您尝试使用它时会收到内部服务器错误。

When mod_rewrite is invoked, the path has already been decoded as part of Apache's request processing. So, if you want to check for a space, you can do so literally:

RewriteRule file\ name\.html http://example.com/new_name.htm#anchor [R=301,NC,NE,L]

The NU flag doesn't exist, which is why you get an internal server error when you try to use it.

生活了然无味 2024-10-01 06:27:11

不是最好的答案,只能在特定情况下使用,但我更改

file%20name.htm

file.*

,以便它将匹配以“文件”开头的任何文件名,无论空格和特殊字符如何。

Not the best answer, and can only be used in specific cases, but I changed

file%20name.htm

to

file.*

so it will match any filename that starts with "file", regardless of spaces and special chars.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文