Need help with .htaccess and 301 Redirect

Status
Not open for further replies.

Divvy

Active Member
806
2009
18
0
Hi guys,

I need some urgent help... maybe someone can help me!

I have a wordpress website and the traffic was going fine!
But since I removed something from my URLs, I received many notifications on webmaster tools about 404 errors and my traffic has dropped from 400 daily to only 30.

My old url was:
domain.com/reviews/post_title

Now is:
domain.com/post_title

So what I did was removing the /reviews/ from the URL.

I notice that in google search results, all urls that appears is without /reviews/ but my SEO guy said that is better to do a 301 redirect so I can recover my traffic back.

I have read this advice from Matt Cutts:
https://support.google.com/webmasters/answer/93633?hl=en

And he said that I need to fix this via htaccess right?
I need to get all of the listed 404s in webmaster tools 301 redirected to the proper url so that I can mark all as fixed, right?

Does anyone know the command to do that?
Only need to redirect 404 urls to new working urls.

From this:
domain.com/reviews/post_title

To this:
domain.com/post_title

Btw, this is my htaccess content:
Code:
# BEGIN WordPress<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


# END WordPress

Anyone? Please?

Thank you!

Best regards,
Divvy
 
Last edited:
8 comments
This should do it:
Code:
# BEGIN WordPress<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^reviews/(.*)$ http://example.com/$1 [R=301,L]
RewriteRule . /index.php [L]
</IfModule>


# END WordPress
 
Hi, thank you for your reply my friend.

I forgot to tell something about my old urls... all of them ends in a .php
So the changes was:

From this:
domain.com/reviews/post_title.php

To this:
domain.com/post_title/

Is that command above works anyway?
 
Thank you so much deliteblogger! :)
Is now working perfectly!

I only added www. before example.com. Is fine right?

Btw, what the "L" means?
And why did you add (.*) ?

Just trying to understand and learn :)

Thank you once again buddy!
 
Hmmm Im having problems with the code that I added.

For example, when I go to:
Code:
http://www.domain.com/wp-admin/
Appears this error message:
This webpage has a redirect loop

And when I try to go to:
Code:
http://www.domain.com/wp-admin/widgets.php
Appears:
404 Not Found

If I remove the code:
Code:
RewriteRule ^reviews/(.*)\.php$ http://example.com/$1/ [R=301,L]

I don't have this issues anymore...
Any ideas, please?
 
The [L] flag causes mod_rewrite to stop processing the rule set. In most contexts, this means that if the rule matches, no further rules will be processed.
(.*) Period means any character, and the asterisk means 0 or more times, the parantheses is to capture that part, to reinsert it later with $1.

I'm not sure what is causing the errors. Try putting the line right after RewriteBase /.
 
Status
Not open for further replies.
Back
Top