0

This type of question has been asked in SO before but the offered solutions do not work for me. How can I remove this directory/folder from url with htaccess rewrite?

I have a multi site wordpress install that I have inherited and it has a single .htaccess file in the root directory of the site.

I need to do a global redirect on all URLs like this http:thewebsite.com/jol/blog/author/myles/ to go to http:thewebsite.com/jol/author/myles/

So far I have tried this code in the .htaccess file:

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# Remove subdirectory of "blog" from URLs
RewriteCond %{THE_REQUEST} \ /blog/
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

and this code:

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{THE_REQUEST} \ /blog/
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

and lastly, this code:

# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^blog/(.*)$ /$1 [R=301,NC,L]

and absolutely none of them work at all. The only thing that has been successful so far is targeting each URL individually and performing a redirect, which is...PAINFUL.

Any help would be hugely appreciated.

Community
  • 1
  • 1
Ryan Coolwebs
  • 1,611
  • 5
  • 22
  • 44

1 Answers1

1

The rules which you tried were not working because you had had: ^blog/ in your patterns. Since the URLs you wanted to rewrite are of the form jol/blog/..., the rule should be updated.

Assuming that jol may vary; use the rule:

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

and if jol will always be in the rules, just use that:

RewriteRule ^jol/blog/(.*)$ jol/$1 [R=301,L,NC]
hjpotter92
  • 78,589
  • 36
  • 144
  • 183