1

I just had to add a 301 redirect to a old dev site and it did not go as smoothly as I'd have assumed. I added the redirect to my htaccess file, backed up the old one and nothing worked.

Turned out that Magento somehow overwrites the htaccess file (at least the redirect parts of it) and caused me some headaches.

The other Devs and me decided we were going to start adding password protection via htaccess on all out development sites and I am trying to find out how I can do this given Magento keeps ignoring what I add into my htaccess files.

To clarify the only way i got the 301 redirect to work was by deleting local.xml off my server, cutting off Magentos database access. Do I have to worry about Magento changing any password settings i add to my htaccess files as well?

  • Would it be possible to do this in the vhost file rather than the htaccess? – David Manners Oct 4 '13 at 15:23
2

Magento's default .htaccess file uses the following RewriteRule:

RewriteRule .* index.php [L]

If you notice, the [L] flag is being set. Read how the [L] flag works.

The [L] flag means "do not process any rules below in this iteration".

So if you are placing any rewrite rules below the above Magento rule, they will not be met.

Your best bet is going to the top of your .htaccess file, and adding in your rules there.

###########################################
## Custom Rewrite Rules
RewriteEngine On
RewriteCond ....
RewriteRule .... [F,L] 

[...]

RewriteRule .* index.php [L]

If your concern is blocking access to your development sites, I would recommend using the built in maintenance mode flag Magento offers.

To simplify enabling and managing access to the development site, you can use the Store Maintenance extension which will allow you to block your site with a custom page and message, and include IP addresses of the people who can bypass the maintenance mode page.

  • Actually I cleared the entire htacess file and only had a single line 301 redirect. I only got it working by removing the DB connection so it doesn't look like a problem with htaccess but magento. – Chris Morris Oct 4 '13 at 15:34
  • I've updated my answer with another solution. Try using the Store Maintenance extension to accomplish your goal. You can modify the template in the settings to include a javascript redirect, like: <script type="text/javascript"> window.location = "http://www.google.com/" </script> – Axel Oct 4 '13 at 15:38

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.