The full .htaccess file
Following is my full htaccess file.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#redirect index to homepage
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#prevent hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?www.example.com [NC]
RewriteRule .(jpg|jpeg|png|gif)$ - [NC,F,L]
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]
#prevent access to wp-config
<files wp-config.php>
order allow,deny
deny from all
</files>
</IfModule>
The directive in question
The following one is obviously the one in question:
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]
Expected outcome
If I go to http://subdomain.example.com/galleries/headshots/
the server should redirect to http://subdomain.example.com/portfolio/headshots/
What happening instead
Nothing at all happens, I remain on http://subdomain.example.com/galleries/headshots/
.
What I have tried so far without success
I added slashes at the end of both, the source and target – nothing changed:
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$/ /portfolio/$1/ [R=301,NC,L]
Also tried putting the directive on top, just below RewriteBase /
– still no luck.
Notes
Note that this happens on a subdomain (see example url), although I don’t think that has an impact on this behaviour.
This is happening on a WordPress installation, but I have doubts it influences that. All the other directives seem to work fine (react on change).
Edit (from the comment reply to @Panama Jack): Both directories actually exist and are separate pages, but one is only setup as a script, if you like (other pages have to access its gallery).
Slash is in the wrong place. Change this
to this
In your rewrite rule the URL should start with a /.
Besides, the part
(.*)$/
is very strange: you are first looking for anything until the end and then adding a slash. Did you want to limit the rewrite rules to directories? Then why not including the trailing slash in the pattern:(.*)/$
?The below rule would redirect everything below
/galleries/