{"id":4028,"date":"2009-09-11T18:06:04","date_gmt":"2009-09-12T01:06:04","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=4028"},"modified":"2017-12-12T16:14:43","modified_gmt":"2017-12-12T23:14:43","slug":"301-redirects","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/htaccess\/301-redirects\/","title":{"rendered":"301 Redirects"},"content":{"rendered":"

This is the cleanest way to redirect a URL. Quick, easy, and search-engine friendly. Remember HTAccess stuff is for Apache servers only.<\/p>\n

Redirect a single page<\/h4>\n
Redirect 301 \/oldpage.html http:\/\/www.yoursite.com\/newpage.html\r\nRedirect 301 \/oldpage2.html http:\/\/www.yoursite.com\/folder\/<\/code><\/pre>\n

Redirect an entire site<\/h4>\n

This way does it with links intact<\/strong>. That is www.oldsite.com\/some\/crazy\/link.html will become www.newsite.com\/some\/crazy\/link.html. This is extremely helpful when you are just “moving” a site to a new domain. Place this on the OLD site:<\/p>\n

Redirect 301 \/ http:\/\/newsite.com\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

This is the cleanest way to redirect a URL. Quick, easy, and search-engine friendly. Remember HTAccess stuff is for Apache servers only. Redirect a single page Redirect 301 \/oldpage.html http:\/\/www.yoursite.com\/newpage.html Redirect 301 \/oldpage2.html http:\/\/www.yoursite.com\/folder\/ Redirect an entire site This way does it with links intact. That is www.oldsite.com\/some\/crazy\/link.html will become www.newsite.com\/some\/crazy\/link.html. This is extremely helpful […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3826,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":4164,"url":"https:\/\/css-tricks.com\/snippets\/htaccess\/shock-teenage-gangsters-with-wp-config-redirect\/","url_meta":{"origin":4028,"position":0},"title":"Shock Teenage Gangsters with wp-config Redirect","date":"September 20, 2009","format":false,"excerpt":"Funny email from a reader, that I figured would make a good post: This is a funny redirect. I get one or two visits a day from teenage gangsters trying to enter my server by checking if a wp-config-file exists that is no longer the newest version. I got best\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4030,"url":"https:\/\/css-tricks.com\/snippets\/htaccess\/force-favicon-requests-to-correct-location\/","url_meta":{"origin":4028,"position":1},"title":"Force Favicon Requests to Correct Location","date":"September 11, 2009","format":false,"excerpt":"For whatever crazy reason, perhaps evil-doing site scanners, requets to a web server for a favicon in all known crevasses of the site are fairly common. Since that file probably only actually exists in the root directory of your site, these requests result in a 404. If you server up\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":6256,"url":"https:\/\/css-tricks.com\/snippets\/htaccess\/ipad-detection\/","url_meta":{"origin":4028,"position":2},"title":"iPad Detection","date":"April 23, 2010","format":false,"excerpt":"Of course, the iPad is a pretty large screen and a fully capable browser, so most websites don't need to have iPad specific versions of them. But if you need to, you can detect for it with .htaccess RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$ RewriteRule ^(.*)$ http:\/\/ipad.yourdomain.com [R=301] This will redirect iPad users\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16101,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/redirect-to-ssl\/","url_meta":{"origin":4028,"position":3},"title":"Redirect to SSL","date":"January 28, 2012","format":false,"excerpt":"window.location = \"https:\/\/\" + window.location.hostname + window.location.pathname + window.location.search; You might wanna test if window.location.href doesn't start with \"https\" before doing that, so you don't redirect unless you have to.","rel":"","context":"With 9 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3885,"url":"https:\/\/css-tricks.com\/snippets\/javascript\/redirect\/","url_meta":{"origin":4028,"position":4},"title":"Redirect","date":"September 6, 2009","format":false,"excerpt":"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4280,"url":"https:\/\/css-tricks.com\/snippets\/php\/redirect\/","url_meta":{"origin":4028,"position":5},"title":"PHP Redirect","date":"September 29, 2009","format":false,"excerpt":"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4028"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=4028"}],"version-history":[{"count":9,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4028\/revisions"}],"predecessor-version":[{"id":263789,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/4028\/revisions\/263789"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3826"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=4028"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=4028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}