Search code examples
wordpress.htaccessmod-rewritemultisite

Wordpress Multisite, htaccess 301 redirect for permalink change


I´ve got a running Wordpress Multisite where I want to change the Permalinks and 301 redirect with htaccess. Changing the permalinks in Wordpress isn´t a problem but all the Links that are around to my site would be broken so I want to fix this with 301.

I´m trying to redirect https://subsite.example.com/blog/%postname%/ to https://subsite.example.com/something-nice/%postname%/ where blog isn´t a real directory because of Wordpress.

I´ve tried the following but it doesn´t work:

# subsite Rewrite Rules

RewriteCond %{HTTP_HOST} ^subsite.example.com [NC]

RewriteRule ^blog/(.*)$ ^/something-nice/$1 [R=301,NC,L]

Anyone can help me with that?


Solution

  • RewriteRule ^blog/(.*)$ ^/something-nice/$1 [R=301,NC,L]
    ------------------------|
    

    Remove the ^ at the start of the substitution string.

    You will need to clear your browser cache, since the erroneous 301 (permanent) redirect will have been cached by the browser (and possibly intermediary caches). Test first with a 302 (temporary) redirect to avoid potential caching issues. (That is assuming you put this rule at the top of the .htaccess file.)

    This rule needs to go near the top of the .htaccess file, before the WordPress code block (ie. before the # BEGIN WordPress comment marker). (If you put this rule at the end of the file then it won't do anything, since it won't be processed for such URLs.)