阿帕奇重写URL用空格 [英] Apache Rewrite Urls With Spaces

查看:145
本文介绍了阿帕奇重写URL用空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在由previous开发者建立了一个网站。 这个网站有previously发送链接给用户带空格的URL文件名,例如 http://website.com/docs/this是pdf.pdf 。我现在有固定的这些链接是通过使用PHP的URL编码时生成的链接,因为特别是Internet Explorer用户目前还没有找到在Linux服务器上的文件,因为文件名有通过适当插入在其中的空间(铬和FF的工作产生它们%20到URL中的空格)。

I'm currently working on a website built by a previous developer. This website has previously sent links to subscribers with spaces in the url filenames, for example http://website.com/docs/this is a pdf.pdf. I have now fixed these links as they are generated by using php url encoding when the link is generated, because specifically internet explorer users are not finding the file on the linux server because the filename has spaces in it (chrome and FF work by properly inserting %20 into the spaces in the url).

目前,我正在试图找到一种方法,使用的.htaccess重写这些URL已经在他们的空间重定向到正确的URL。例如,如果用户要求 http://website.com/docs/this是pdf.pdf 的的.htaccess重定向到 http://website.com/docs/this%20is%20a%20pdf.pdf 。请注意,有数以千计的这个服务器上的文档所以这确实需要是动态的。

I'm currently trying to find a way to use .htaccess to rewrite these urls that have spaces in them to redirect to the correct url. For example, if a user were to request http://website.com/docs/this is a pdf.pdf the .htaccess will redirect to http://website.com/docs/this%20is%20a%20pdf.pdf. Note that there are thousands of documents on this server so this does need to be dynamic.

有什么我试过吗?

我已经看了和的这个多,但不能添加更多的联系,因为这么说,我没有足够的声誉。

I've looked at this and this and more, but can't add more links because SO says I don't have enough reputation.

这些选项似乎表明,它是可能的,如果你在事先知道的文件名会。我需要这是动态的。任何人在那里有什么想法?

These options seem to show that it is possible if you know in advance what the filename will be. I need this to be dynamic. Anyone out there have any ideas?

推荐答案

把空间逃脱大括号,例如..

Put the spaces escaped inside braces, for example..

RewriteRule ^(.+)(\ )(.+)(\ )(.+)(\ )(.+)\.pdf /$1-$3-$5-$7.pdf

将捉对任何四个字file.pdf任何请求,并把它改写为/any-four-word-file.pdf

would catch any request for "any four word file.pdf" and rewrite it to /any-four-word-file.pdf

O)肺心病

这篇关于阿帕奇重写URL用空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆