4

I usually update Core with Drush, because it's so easy and wonderful, but I have a custom htaccess and it always overwrites it, forcing me to rely on a checklist where I have to go and put my custom one back in. Is there a way I can either tell Drush not to overwrite it when updating or automatically put the custom one back in with a bash script or something? Or should I use a module to do these redirects instead? They are all like this and are a legacy from when our main company website hosted some custom apps:

RedirectMatch 301 ^/blah/ blah blah.cgi http://anotherwebsite.com/cgi-bin/blah.cgi

6
  • 4
    This would be a good feature request to put in the Drush issue queue. I usually like to put my rewrite rules and such in Apache configuration files, so that .htaccess can remain clean. If you're on a shared hosting plan, though, that is not an option. If you started an issue in the queue, or better yet, started an issue and included a simple patch, others might collaborate with you on a solution. – greg_1_anderson Oct 22 '12 at 17:28
  • I will start an issue on the queue. I'm not on shared hosting, but where do I configure this in Apache? – Melissa Oct 22 '12 at 17:41
  • here is a discussion that seems related drupal.org/node/1170058 – Melissa Oct 22 '12 at 17:41
  • @Melissa, post the drush issue here if you open it; I may be interested in taking on the patch. BTW, you should really use RewriteRule instead of RedirectMatch for old paths. Mixing mod_rewrite and mod_alias can behave oddly because of the Apache execution order for modules. – mpdonadio Oct 22 '12 at 18:46
  • @greg_1_anderson, I thought this seemed familiar. It appears that this got suggested and was closed as a "won't fix": drupal.org/node/1018190 – mpdonadio Oct 22 '12 at 18:57
5

Short of support directly in Drush, this is what I would recommend.

Keep your site in a structure something like this:

  • srv
  • . www
  • . . mysite.com
  • . . . .git
  • . . . custom-htaccess
  • . . . custom-robots.txt
  • . . . htdocs
  • . . . . .htaccess
  • . . . . robots.txt
  • . . . . ... other files in the Drupal root

I like to structure my Drupal files as shown above so that I have a place to keep files in the same git repository as my Drupal files without exposing them to the webserver (or worrying about hiding them from the webserver with custom .htaccess rules).

If you keep all of your customizations to .htaccess and robots.txt in separate files like this, it would be an easy thing to concatenate them on the end of the corresponding Drupal core files. This structure might be a good starting point for a formal Drush feature that does the same thing.

Update: If you are not on shared hosting, you'll do much better to store your .htaccess customization on the Apache vhost conf file, and leave Drupal's .htaccess file unmodified. The syntax of this file is about the same as the .htaccess file. The first step is to find the right file; it's often in /etc/apache2/vhost.d or /etc/httpd/vhost.d, although on Debian distros such as Ubuntu it is in /etc/apache2/sites-available. Apache configuration is not a Drupal-specific topic; there's a lot of info about it available on the Internet.

0

Another solution here is using the htaccess module to maintain your configurations outside the file. The module stores different htaccess profiles and lets you deploy them as you need it. Each profile contains options (e.g. www or no-www redirect) and a list of htaccess directives, helpful when you have a litany of legacy URLs to redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.