I'm pasting my full htaccess file, for clarity, as to be honest, I'm not entirely sure if I have to include my non-default directives inside the <IfModule mod_rewrite.c> bits or separately (below - I've seen it somewhere).

<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

The relevant bit is this one:

#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]

Now, if I go to http://subdomain.example.com/galleries/headshots/ I'm expecting it to redirect to http://subdomain.example.com/portfolio/headshots/, but instead nothing at all happens.

I even tried the following (adding slashes at the end of both, the source and target):

#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$/ /portfolio/$1/ [R=301,NC,L]

Also note that I'm using a subdomain, but I wouldn't expect that to be an issue.

Does the L bit in the directives above count? I understand those are to tell the script to stop execution of anything after.

  • It is not making it to your rule. Put it higher up before the "#redirect index to homepage"
    – user42826
    Mar 13, 2015 at 8:25
  • Sorry, @user42826, no luck :(
    – benomatis
    Mar 13, 2015 at 9:12
  • Works for me. Maybe your web server is not using/allowing htaccess files. The easiest way to tell is to put junk in there and try to access any url. Just type in "breakme" in .htaccess You should be a 500 error in the browser.
    – user42826
    Mar 13, 2015 at 19:49
  • @user42826 see my answer...
    – benomatis
    Mar 13, 2015 at 20:44

1 Answer 1


With some help (also asked on SO, as this wasn't a strict WP question), and some testing, the following ended up working for me (added a slash just before the $ sign):

RewriteRule ^galleries/(.*)/$ /portfolio/$1 [R=301,NC,L]

As the galleries are actual directories, not files, they have a slash at the end:

                                        Here ---^

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.