301 redirect code

by 5 replies
6
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
#programming #301 #code #redirect
  • 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:

    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)
  • 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.
    • [2] replies
    • 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)
    • 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.
  • 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

Next Topics on Trending Feed

  • 6

    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