How to use remote images to reduce workload when Drupal is developing

Source: Internet
Author: User
Tags drupal

If you have met a large-scale Drupal project, you may have found that the files directory is too large to be a huge challenge to development. How to keep the development server (or your personal computer) synchronized with these files is a very painful thing, but if you do not, often because the user uploaded files or attachments can not be used, so that many important issues in the site development process can not be found.

There are many ways to solve this problem, but it is either very slow or very complex. For example, use the Drush command or use a script to download a Web site's files and upload them to the local development environment, or even consider using FTP to do so (please do not do so). Although these methods can be effective, I still hope to save valuable time and hard disk space.

At first we found the Stage file Proxy module, which allows Drupal to direct all file requests to the online server, even if the site is running locally. But for this module to work properly, you need to make some adjustments to the site and install additional modules. So, although this module can solve the problem, I still hope to have other solutions.

Later, we found that we could use Apache's URL rewrite rules to satisfy our needs--when the Apache program was processing a connected Web request, the rewrite rule allowed it to modify the URL address that satisfies the specified rule--for example, it could redirect requests to the local files directory to a server on the line.

After looking for posts and tutorials on URL rewrite rules, we can finally write the code we need. Because I use MAMP for development, it is much easier to add Apache configuration snippets than to install modules. At the same time this method does not need to modify the site settings, and do not need to enable the new module. If you are not using MAMP as the development environment, Apache overrides configuration code settings may be slightly different. In fact, the following configuration snippet is pasted into the Apache website configuration section.

Here's a sample code that lets Drupal use remote files when developing:

# # Apache Rewrite

Rewriteengine on

# Force image Styles This has local files that exist to be generated.

Rewritecond%{request_uri} ^/sites/([^\/]*)/files/styles/[^\/]*/public/((. *)) $

Rewritecond%{document_root}/sites/%1/files/%2-f

Rewriterule ^ (. *) $ $ [qsa,l]

# Otherwise, send anything else that's in the files directory to the

# production server.

Rewritecond%{request_uri} ^/sites/[^\/]*/files/.*$

Rewritecond%{request_uri}!^/sites/[^\/]*/files/css/.*$

Rewritecond%{request_uri}!^/sites/[^\/]*/files/js/.*$

Rewritecond%{request_filename}!-f

Rewritecond%{request_filename}!-d

Rewriterule ^ (. *) $ http://www.example.com/$1 [qsa,l]

If you are using Mamp for development, open Mamp, find "Custom virtual host Settings" at the bottom of the advanced panel, paste the above code into it and save it (note that the example.com in the code is changed to your own domain address).

Finally, just restart Aapche to let Drupal locally developed site directly use remote files, and I can save the hard disk space to put more cat pictures.

The original title: How to use the remote image to lighten the workload when Drupal is developing

Original address: http://drupalct.org/drupal-development/use-remote-images-and-files-for-local-drupal-development.html

How to use remote images to reduce workload when Drupal is developing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.