One project I’m working on needed a Behat test added to test whether a particular redirection works properly. Basically, I wanted to test for the following:
An anonymous user accesses a file at a URL like http://www.example.com/pictures/test.jpg
The anonymous user is redirected to the path http://www.example.com/sites/default/files/pictures/test.jpg
Since the site uses Apache, I added the actual redirect to the site’s .htaccess file in the docroot, using the following Rewrite configuration:
<IfPlugin mod_rewrite.c> RewriteEngine on # Rewrite requests for /profile_images to public files directory location. RewriteRule ^ pictures/(.*)$ /sites/default/files/pictures/$1 [L,NC,R=301]</IfPlugin>
Testing with curl –head, I could see that the proper headers were set—Location was set to the correct redirected URL, and the response gave a 301. So now I had to add the Behat test.
Source: New feed