使用 htaccess 重写特定文件的路径 [英] Rewriting path for a specific file using htaccess
问题描述
我想为具有长文件路径的目录中的特定文件创建一个友好的 url,并重命名该文件.我什至不确定这是否可能.
I would like to create a friendly url for a specific file from a directory that has a long file path as well as renaming the file. I am not even sure if this is possible.
到目前为止,我已经在 htaccess 中尝试过:
So far I have tried in htaccess:
RewriteEngine On
Options +FollowSymLinks
RewriteRule eventdays-2012/brochure.pdf(.+)$ sites/default/files/docs/fact_sheet-204499207.pdf
...但这不起作用.
我已经进行了一些搜索,并查看了可以在文件路径中屏蔽整个目录的位置,但在我的情况下,我只想在目录中创建一个文件,创建一个目录名并更改文件名.
I've done some searching and see where you can mask an entire directory in the file path but in my case I just want to do one file within the directory, create a directory name and change the file name as well.
推荐答案
尝试从正则表达式中删除 (.+)
部分.它使您在 brochure.pdf
之后需要一些东西.还要添加一些边界:
Try removing the (.+)
part from your regular expression. It makes it so you need something after the brochure.pdf
. Also add some boundaries:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^/?eventdays-2012/brochure.pdf$ /sites/default/files/docs/fact_sheet-204499207.pdf [L]
这篇关于使用 htaccess 重写特定文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!