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
- The anonymous user is redirected to the path
Since the site uses Apache, I added the actual redirect to the site's
.htaccess file in the docroot, using the following Rewrite configuration:
# Rewrite requests for /profile_images to public files directory location.
RewriteRule ^ pictures/(.*)$ /sites/default/files/pictures/$1 [L,NC,R=301]
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.