Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make i18n support filenames in Drupal 7?

So i have a standard file located at:

/sites/default/files/hello.png

I can access it like so:

http://www.example.com/sites/default/files/hello.png

However, with i18n, it would be nice if the prefixed paths would also work for these files. For example, this link doesn't work:

http://www.example.com/us/sites/default/files/hello.png

But it doesn't.

So my question is, how can I make these "country-specific" paths also work for files?

I am thinking I might need to do something in htaccess and then also create a module that filters and redirects these paths, but that just sounds like way too much effort and that perhaps I am missing the easy way to enable this?

like image 571
coderama Avatar asked Jun 26 '15 10:06

coderama


1 Answers

You can use htaccess to make all language-version URLs redirect to the default URL for files/images. If you do this you won't need to do anything further in your drupal code (e.g. a custom module).

Your rewrite rule would look like this

RewriteEngine On
RewriteRule ^([a-zA-Z-]*)/sites/default/files/(.*)$ sites/default/files/$2 [R=301,L]

Updated

If your site is in a subdirectory e.g. 'drupal', you could modify your rewrite rule like this

RewriteRule ^drupal/([a-zA-Z-]*)/sites/default/files/(.*)$ drupal/sites/default/files/$2 [R=301,L]
like image 58
Scott Anderson Avatar answered Oct 30 '22 01:10

Scott Anderson