Matthew Blewitt
Matthew Blewitt

Reputation: 487

Redirect all url from folder to root but keep folder unchanged

I have a website and want to permanently change the url structure from:

www.mysite.com/blog/post-name/

www.mysite.com/post-name/

I found a solution:

RewriteRule ^blog/(.*)$ http://www.mysite.com/$1 [R=301,L]/

The only thing is I want to be able to keep www.mysite.com/blog/ as a page without it redirecting to www.mysite.com/

Can't figure this one out.

Many Thanks,

Upvotes: 1

Views: 158

Answers (2)

anubhava
anubhava

Reputation: 785146

Have your rules like this:

RewriteEngine On

RewriteCond %{THE_REQUEST} /blog [NC]
RewriteRule ^blog(/.*)?$ $1 [L,R=301,NC,NE]

RewriteRule ^((?!blog/).*)$ /blog/$1 [L,NC]

Upvotes: 1

Howli
Howli

Reputation: 12469

Removing the R=301 from the rewrite rule should fix that. The rule would be:

RewriteRule ^blog/(.*)$ http://www.mysite.com/$1 [L]

Upvotes: 0

Related Questions