Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Htaccess blog redirect WordPress

  • SOLVED

Hi,

I need a permalink/htaccess redirect issue solved.

Previous/current permalink structure: /blog/%year%/%monthnum%/%day%/%postname%/

New permalink structure: /%year%/%monthnum%/%day%/%postname%/

I need the htaccess code that will properly 301 redirect all posts

/blog/%year%/%monthnum%/%day%/%postname%/ to /%year%/%monthnum%/%day%/%postname%/

and /blog/category/%cat-name% to /category/%cat-name%


Thanks!


UPDATE: forgot to mention it is a multisite installation

Answers (4)

2010-12-20

Lew Ayotte answers:

Add this to the top of your .htacess file:

RewriteCond %{REQUEST_URI} /blog/.+
RewriteRule ^blog/(.*)? http://yoursite.com/$1 [R=301,L]


Joachim Kudish comments:

That works really great for posts but not for categories

blog/category/%cat-name%/ this results in a 404.

Any ideas?


Joachim Kudish comments:

That works really great for posts but not for categories

blog/category/%cat-name%/ this results in a 404.

Any ideas?


Lew Ayotte comments:

That doesn't really make sense... what is the URL it redirects to for a category?


Joachim Kudish comments:

You can take a look for yourself here:

http://www.nearshoreamericas.com/blog/category/expert-views-commentary/

this should redirect to http://www.nearshoreamericas.com/category/expert-views-commentary/

but it currently doesn't with your code in the htaccess


Lew Ayotte comments:

Do you currently have a .htacess file in /blog/ ? If so, can you rename it to bak.htaccess or something...

Also, what does your current .htaccess file look like in /?


Joachim Kudish comments:

no there is no .htaccess in /blog/ in fact there is no such folder at all.

the current .htaccess file in the main folder looks like this:



RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]

RewriteCond %{REQUEST_URI} /blog/.+
RewriteRule ^blog/(.*)? http://yoursite.com/$1 [R=301,L]

php_value max_execution_time 60000
php_value upload_max_filesize 300M
php_value upload_max_size 300M
php_value post_max_size 300M



Lew Ayotte comments:

What if you put:

RewriteCond %{REQUEST_URI} /blog/.+
RewriteRule ^blog/(.*)? http://yoursite.com/$1 [R=301,L]

At the very top? Above everything else.

By the way, I assume you replaced "yoursite.com" with "www.nearshoreamericas.com"?


Joachim Kudish comments:

Yes I replaced it to the correct domain name.

I tried adding it to the top as you said, now I get redirected to this url: http://www.nearshoreamericas.com/wp-signup.php?new=nearshoreamericas.com when visiting http://www.nearshoreamericas.com/blog/category/expert-views-commentary/

seems kind of random. ideas?


Lew Ayotte comments:

ah, this is a Multi-Site install?


Joachim Kudish comments:

yes it is


Lew Ayotte comments:

Did you include the "www." in the redirect? If not, you should.


Joachim Kudish comments:

I added it and it worked. Thanks for your quick responses Lew!

2010-12-20

Rashad Aliyev answers:

Hello you can use it with easy method. Redirection plugin. http://wordpress.org/extend/plugins/redirection/


Joachim Kudish comments:

I specifically don't want a plugin but just a simple htaccess way

2010-12-20

MagoryNET answers:

Try this:

<blockquote>
RewriteEngine On
RewriteRule ^blog/(.+) /$1 [L]
</blockquote>

edit: well, Lew was faster. :)


Joachim Kudish comments:

Same problem as above

That works really great for posts but not for categories

blog/category/%cat-name%/ this results in a 404.

Any ideas?

2010-12-20

Roberto Mas answers:

http://wpshout.com/a-to-z-of-wordpress-htaccess-hacks/