5 replies
Hi -
Trying to find out the correct code to do a 301 redirect of the double u version of a site to the non double u version. I find conflicting things when i just goolge it. I am not a coder so i just need it spelled out for me.
And also a /...htm file to the main page of the site

(sorry _ ia can't post links so previous attempts at making this post clearer did not work)
thanks
A
#301 #code #redirect
  • Profile picture of the author luminousnerd
    You have to access your .htaccess file. Most likely you will find it in your public_html directory, you may have to enable hidden files to see it. There's a good chance you don't have one yet, in which case you can just create a plain text file and name it .htacces, and put this code in it:

    Redirect 301 /old/old.html http://www.you.com/new.html
    The /old/old.html, obviously, is the path to thepage, with the full URL being the page you want to redirect to.

    Once you have a .htaccess file with that code and the proper addresses, upload it to your site's root (usually public_html)
    {{ DiscussionBoard.errors[2372301].message }}
  • Profile picture of the author ShelbyC
    If you want to redirect http://site.com to http://www.site.com you would use this code:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{http_host} ^sitename.com [NC]
    RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,NC]
    
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://sitename.com.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.sitename.com.*$ [NC]
    RewriteRule .(gif|jpg|png)$ - [F]
    If you're looking to move a page and properly inform the search engines the code from luminousnerd will work perfectly for that.

    To access your htaccess file just go into your site administration area and use file manager or it's equivalent with the option to enable hidden files to be seen - on.

    Then add the code above which will rewrite your url to always include the www.

    Don't forget to replace sitename with your website domain name.
    Signature

    {{ DiscussionBoard.errors[2372583].message }}
    • Profile picture of the author lakelover339
      thanks - I have seen variations of this so wasn't sure what was correct. So I need ALL of that code, I guess?

      I am actually trying to go the opposite direction in most cases ( to non- www)
      {{ DiscussionBoard.errors[2383826].message }}
    • Profile picture of the author lakelover339
      Does anyone know how this works with wordpress? In WP general settings, you specific www or non www and it redirects. so I don't understand if I still need the .htaaccess file and if I do, if the WP settings will be compatible.
      {{ DiscussionBoard.errors[2383834].message }}
  • Profile picture of the author pbarnhart
    SHelbyC's code can be modified like:

    RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
    RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

    for the www to non-www
    {{ DiscussionBoard.errors[2384189].message }}

Trending Topics