当前位置: 动力学知识库 > 问答 > 编程问答 >

.htaccess - Rewriting path for a specific file using htaccess

问题描述:

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.

So far I have tried in htaccess:

RewriteEngine On

Options +FollowSymLinks

RewriteRule eventdays-2012/brochure.pdf(.+)$ sites/default/files/docs/fact_sheet-204499207.pdf

... but this is not working.

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.

网友答案:

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]
分享给朋友:
您可能感兴趣的文章:
随机阅读: