开发者

301 redirection help on wordpress

I'm searching for a 301 redirect rules in .htaccess for the last one week. I have visited many similar pages here too. But all are not working for me. So I'm asking help from masters like you.

I'm using wordpress blogging platform. Before I was using Joomla and that time so many 404 errors was there on my website. There are more than 10,000s of 404 errors. Mainly two category of 404 errors. Examples are example.com//component/option,com_xmap/Itemid,44/component/xxx/yyy/menu1/menu2/something/ and example.com/index.php/component/option,com_xmap/Itemid,44/component/xxx/yyy/directory/menu1/menu2/something.html. Like these too many urls. I think this happened due to some cache problem in Joomla and these urls were created one by one on the homepage of a module. After I disabled cache for that module the problem was solved, but google indexed all these bad urls already.

I think it's better to do a 301 redirect for those two categories of 404 error urls to the homepage or to www.freezonal.com/sitemap.xml since these urls are only indexed by google and are not seen in search results.

Currently I'm using this on my .htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule 开发者_运维技巧. /index.php [L]
</IfModule>
# END WordPress

RewriteCond %{QUERY_STRING} .*
RewriteRule ^index.php/(.*)$ /? [R=301,L]

Is there any 301 redirection code for redirecting those two categories of 404 urls to the main website and is there any other suggestion for better SEO. I'll be very thankful to you, if you solve this.


First, WordPress' rewrite rules must be on the bottom, because they slurp up any 404s. Anything after them isn't going to work correctly. So add new rules above WordPress' rules.

RewriteEngine On
RewriteBase /
RewriteRule (index.php/|/)?component/option http://example.com/ [L,R=301]

Something like that should work. I don't know if you want to keep any of your /component/ URLs working, so you may need to remove the question mark from the RewriteRule.


In order for the rewrite to work, make sure that you wrap your rewrite conditions in the mod_rewrite.c tags. Then turn turn on RewriteEngine and set your RewriteBase. I don't think the redirects work outside of the mod_rewrite tags.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .*
RewriteRule ^index.php/(.*)$ /? [R=301,L]
</IfModule>

If you only want to only redirect these two paths to the homepage, try this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^component* / [R=301,L]
RewriteRule ^index.php/component* / [R=301,L]
</IfModule>

Try that out and see if it works.

Also, be sure to check out the documentation on apache.org here http://httpd.apache.org/docs/current/mod/mod_rewrite.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜