重写路径使用htaccess的一个特定的文件 [英] Rewriting path for a specific file using htaccess

查看:215
本文介绍了重写路径使用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

...但是这是行不通的。

... 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.

推荐答案

尝试删除(+)部分从常规的前pression。它使得你的需要的东西AFTE rthe brochure.pdf 。另外补充一些界限:

Try removing the (.+) part from your regular expression. It makes it so you need something afte rthe 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屋!

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