Rewriting a path for a specific file using htaccess

I would like to create a friendly url for a specific file from a directory with a long file path, and also to rename the file. I'm not even sure that 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 it does not work.

I did some searching and see where you can mask the entire directory in the file path, but in my case I just want to make one file in a directory, create a directory name and change the file name.

+4
source share
1 answer

Try removing the part (.+) From your regular expression. It makes you need something after brochure.pdf . Also add some borders:

 RewriteEngine On Options +FollowSymLinks RewriteRule ^/?eventdays-2012/brochure.pdf$ /sites/default/files/docs/fact_sheet-204499207.pdf [L] 
+4
source

Source: https://habr.com/ru/post/1437490/


All Articles