Matt Steele
Matt Steele

Reputation: 655

Create a redirect that removes a segment from a URL

I'm changing the URL structure on a site and need to set a 301 to force users to the new URL.

I want to go from:

http://website.com/blog/single/name-of-entry

to:

http://website.com/blog/name-of-entry

I'd like to remove the segment single.

I've been searching, but haven't found anything that's worked yet. I think I've gotten close with this code:

RewriteRule ^(.*?)/?single(.*)$ /$1$2 [L]

Any ideas?

Upvotes: 1

Views: 42

Answers (1)

anubhava
anubhava

Reputation: 785266

You can use this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^(.+?)/single/(.*)$ /$1/$2 [L,NC,R=301]

Upvotes: 1

Related Questions