Submit Your Article Forum Rules

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Need help on wordpress .htaccess

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    106

    Need help on wordpress .htaccess

    Could anyone give me some idea about how to fix the .htaccess matter? Thanks in advance.

    As we know that for search engines, the repeated content is so bad for a site. Unfortunately search engines usually treat http:// www. example. com, http:// example. com and http:// www. example. com/index.php as different pages. So the problem occurs because the three above mentioned urls might lead to the same page. In this case, search engines would just pick one of them randomly to decide the serps.

    My situation is that I have done most of the backlinks based on http:// www. example. com, but my default url is http:// example. com. I was wondering if search engines would ignore all those backlinks or not? Now I would like to use 301 in .htaccess to fix the problem in my wordpress blog. Is it possible and how?

    Any your idea would be appreciated!

  2. #2
    WebProWorld MVP danlefree's Avatar
    Join Date
    Jun 2005
    Posts
    414

    Re: Need help on wordpress .htaccess

    The following may be useful:

    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    # Host rewrite
    RewriteCond %{HTTP_HOST} !^yourdomain\.com [NC]
    RewriteRule .? http://yourdomain.com%{REQUEST_URI} [R=301,L]
    
    # wordpress standard rewrite
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    I would recommend a search for a wordpress Canonical URL Plug-in to take care of the remainder of your concerns.
    Dan LeFree | Owner/Operator (Web development, marketing)

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    106

    Re: Need help on wordpress .htaccess

    HI Danlefree, thanks so much for your suggestion. But something wrong happened after I added that code to my.htaccess. It told that it can not redirect to the target URL. I have tried many other methods, but it just did not work for me. I think I have to give it up now. Anyway, thanks just the same.

  4. #4

    Re: Need help on wordpress .htaccess

    You should setup www. or without www domain in webmaster tools. Install All-in-one seo pack and setup this tool for canonical url's.

  5. #5
    Senior Member
    Join Date
    Sep 2009
    Posts
    104

    Re: Need help on wordpress .htaccess

    Quote Originally Posted by nichita2008 View Post
    You should setup www. or without www domain in webmaster tools. Install All-in-one seo pack and setup this tool for canonical url's.
    Although you "should" set your preferred domain in Google's WMT, this does not fix the URL canonicalization issues for all of the OTHER search engines. It only fixes it for Google.

    You should definitely be fixing this with 301 redirects, preferably with Mod_Rewrite and .htaccess files. You're on the right track.

    I typically use the following at the very bottom of my .htaccess in the root of my webs:

    RewriteCond %{HTTP_HOST} ^example.com$ [NC]
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    if the www version is chosen as the canonical URL.

  6. #6

    Re: Need help on wordpress .htaccess

    The Platinum SEO Pack adds the canonical tag automatically, plus has all the features the All in One SEO plugin has... highly recommended.

    As for Wordpress, in the settings you can indicate the URL (with or without www) and it will automatically correct the URL for you when someone visits your site.
    Be Sure to Visit FoundByDesign.com and EdNailor.com

  7. #7
    Senior Member
    Join Date
    Sep 2009
    Posts
    104

    Re: Need help on wordpress .htaccess

    I'm pretty sure though if you have wordpress redirect, it's a 302. And you want a 301. But maybe it was my theme doing the 302. Not 100% sure. I would definitely check the "type" of redirect if you're counting on WP to handle it.

  8. #8

    Re: Need help on wordpress .htaccess

    The redirection plugin will also allow you to manually add the 301 redirect from www to non www if needed.
    Be Sure to Visit FoundByDesign.com and EdNailor.com

  9. #9
    Senior Member
    Join Date
    Apr 2009
    Posts
    106

    Re: Need help on wordpress .htaccess

    Thanks for all above comments. Canonical and FoundBydesign gave their very constructive opinions. I agree that it's a 302 in wordpress redirect. And I have tried that codes and I think at least the half problem solves. The other half problem of http:// www. example. com/index.php is still there. I am pretty sure that the redirection plugin will work. But I prefer the code to the plugin.

  10. #10
    Senior Member
    Join Date
    Sep 2009
    Posts
    104

    Re: Need help on wordpress .htaccess

    This may not be the most efficient way to do this (there is probably a way to generalize RewriteRule 1 for the home page index.php with RewriteRule 2 for all other index.php on your site) however this should do the trick AND handle the non-www to www.

    # handle root index.php as a special case
    RewriteCond $1 ^index\.php$ [NC]
    RewriteRule (.*) http://www.mysite.com/ [R=301,L]

    # handle all other index.php files on web
    RewriteCond $1 (.*)/$ [NC]
    RewriteRule (.*)index.php$ http://www.mysite.com/%1/ [R=301,L]

    # handle non-www to www
    RewriteCond %{HTTP_HOST} ^example.com$ [NC]
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    Note: This will redirect http://www.example.com/index.php to http://www.example.com/ WITH the trailing slash. It will also redirect http://www.example.com/folder/index.php to http://www.example.com/folder/ WITH the trailing slash. I like to always include the trailing '/' on my URLs where I'm referencing a folder that contains a default document. It's just one of my preferred canonicalization rules.

    If you don't like trailing slashes then the rewriterules/rewriteconditions will need to be tweaked a bit.

    Hope this helps.

Page 1 of 2 12 LastLast

Similar Threads

  1. Wordpress SEO & Security Friendly .htaccess & Pugins
    By Webnauts in forum Internet Security Discussion Forum
    Replies: 23
    Last Post: 03-29-2012, 08:50 AM
  2. 301 reditects, .htaccess and Wordpress
    By morestar in forum IT Discussion Forum
    Replies: 24
    Last Post: 11-24-2009, 07:02 PM
  3. WordPress htaccess issues
    By imsickofwebpro in forum Web Programming Discussion Forum
    Replies: 6
    Last Post: 01-18-2008, 09:59 PM
  4. Combining my .htaccess rewrites with WordPress rewrites
    By mantawebsolutions in forum Web Programming Discussion Forum
    Replies: 5
    Last Post: 04-05-2007, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •