Thomas Venturini
Thomas Venturini

Reputation: 3750

Redirect /blog/article to /articles/article in .htaccess

As the title says, I want to redirect from my old blog URL to the new one. Here is what I tried:

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

I really thought that this would work but it turns out that I am missing something. If you could help out that would be great.

Upvotes: 0

Views: 59

Answers (1)

MrWhite
MrWhite

Reputation: 45829

The URL-path that is matched by the RewriteRule pattern in a per-directory context (ie. in .htaccess) never starts with a slash because the directory-prefix (that ends with a slash) is first removed. In order words, the regex ^/blog/(.*)$ will never match.

You would need something like the following instead:

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

Note the absence of the slash at the start of the pattern. This contrasts when mod_rewrite is used in a server (or virtualhost) context, then the slash prefix is required.

Upvotes: 1

Related Questions