{"id":645956,"date":"2013-01-19T13:08:50","date_gmt":"2013-01-19T13:08:50","guid":{"rendered":"https:\/\/xptt.com\/?p=645956"},"modified":"2020-02-20T06:05:34","modified_gmt":"2020-02-20T09:05:34","slug":"the-wordpress-most-simple-301-redirect","status":"publish","type":"post","link":"https:\/\/xptt.com\/645956.html","title":{"rendered":"wordpress\u6700\u7b80\u5355\u7684301\u91cd\u5b9a\u5411"},"content":{"rendered":"<p>\u8fd9\u4e2a301\u91cd\u5b9a\u5411\u65b9\u6cd5\u6700\u7b80\u5355\uff0c\u4e5f\u6700\u5bb9\u6613\uff01<\/p>\n<p>\u4e8b\u60c5\u662f\u8fd9\u6837\u7684\uff0c\u4eca\u5929VPS\u7a81\u7136\u762b\u75ea\u4e86\uff0c\u8fd8\u597d\u524d\u4e24\u5929\u505a\u4e86\u5907\u4efd\uff0c\u90e8\u5206\u6570\u636e\u4e22\u5931\uff0c\u5927\u5bb6\u7684\u8bc4\u8bba\u4e5f\u4e22\u4e86\uff0c\u5728\u6b64\u62b1\u6b49\uff0c\u53e6\u5916\u5c31\u662f\u6211\u524d\u51e0\u5929\u5bf9\u4e3b\u9898\u505a\u7684\u4e00\u4e9b\u5c0f\u4fee\u6539\u4e5f\u5f97\u91cd\u65b0\u518d\u505a\u4e86\uff0c\u6700\u90c1\u95f7\u7684\u662f\uff0c\u73b0\u5728\u56de\u5230\u539f\u6765\u7684\u4e3b\u673a\uff0c\u53c8\u5f97\u505a\u4e00\u6b21\u53bb\u6389www\u505a301\u91cd\u5b9a\u5411\uff0c\u7531\u4e8e\u662f\u8861\u5929\u7684linux\u4e3b\u673a\uff0c\u53ea\u6709\u63d0\u4f9bCpanel\u9762\u677f\uff0c\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0c\u6211\u6298\u817e\u534a\u5929\uff0c\u6ca1\u529e\u6cd5\u628a<a href=\"http:\/\/www.xptt.com\">www.xptt.com<\/a>\u91cd\u5b9a\u5411\u5230xptt.com\uff0c\u5f53\u7136\u4e3b\u9875\u53ef\u4ee5301\u91cd\u5b9a\u5411\uff0c\u6587\u7ae0\u9875\u548c\u5176\u4ed6\u9875\u9762\u90fd\u65e0\u6cd5301\u91cd\u5b9a\u5411\uff0c\u771f\u662f\u89c1\u9b3c\uff01<\/p>\n<p><a href=\"https:\/\/xptt.com\/the-wordpress-most-simple-301-redirect.html\/301chongdingxiang\" rel=\"attachment wp-att-645960\"><\/a><\/p>\n<p>\u6211\u7528\u8fc7\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1.Cpanel\u4e0b\u7684\u91cd\u5b9a\u5411\u529f\u80fd\uff0c\u53ef\u60dc\u65e0\u6cd5\u5b9e\u73b0<\/strong><a href=\"http:\/\/www.xptt.com\"><strong>www.xptt.com<\/strong><\/a><strong>\u91cd\u5b9a\u5411\u5230xptt.com\u3002\u5931\u8d25\u3002\u3002<\/strong><\/p>\n<p><strong>2. \u4fee\u6539.htaccess\uff0c\u91cd\u5b9a\u5411<a href=\"http:\/\/www.xptt.com\">www.xptt.com<\/a>\u5230xptt.com\uff0c\u5931\u8d25\u3002\u3002\u3002<\/strong><\/p>\n<blockquote><p>RewriteEngine On<br \/>\nRewriteCond %{HTTP_HOST} !^domain.com$ [NC]<br \/>\nRewriteRule ^(.*)$ http:\/\/domain.com\/$1 [L,R=301]<\/p><\/blockquote>\n<p><strong>3.\u8fd8\u662f\u4fee\u6539.htaccess\u6587\u4ef6\uff0c\u5931\u8d25\u3002\u3002\uff1a<\/strong><\/p>\n<blockquote><p># BEGIN WordPress<br \/>\n&lt;IfModule mod_rewrite.c&gt;<br \/>\nOptions +FollowSymLinks<br \/>\nRewriteEngine on<br \/>\nrewritecond %{http_host} ^www.old.com [nc]<br \/>\nrewriterule ^(.*)$ http:\/\/www.new.com\/$1 [L,R=301]<br \/>\n&lt;\/IfModule&gt;<br \/>\n# END WordPress<\/p><\/blockquote>\n<p>\u6700\u540e\u627e\u6765\u627e\u53bb\uff0c\u8fd8\u662f\u627e\u5230\u4e86zww\u90a3\u91cc\uff08\u771f\u662f\u6709\u7f18\uff0c\u5f88\u591a\u95ee\u9898\u627e\u6765\u627e\u53bb\u6700\u540e\u8fd8\u662f\u5728google\u5230\u4ed6\u90a3\u91cc\uff09\uff0c\u7528\u4e86\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff0c\u8d85\u7ea7\u7b80\u5355\u7684\u5b9e\u73b0\u4e86301\u91cd\u5b9a\u5411\uff01<\/p>\n<p><strong>\u4fee\u6539 wordpress \u6839\u76ee\u5f55\u4e0b\u7684 wp-blog-header.php \uff0c\u5e76\u5728\u6587\u4ef6\u5f00\u5934 &lt;?php \u4e4b\u540e\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801\uff0c\u6210\u529f\uff1a<\/strong><\/p>\n<blockquote><p>if (strtolower($_SERVER['SERVER_NAME'])!='xptt.com')<br \/>\n{<br \/>\n$URIRedirect=$_SERVER['REQUEST_URI'];<br \/>\nif(strtolower($URIRedirect)==\"\/index.php\")<br \/>\n{<br \/>\n$URIRedirect=\"\/\";<br \/>\n}<br \/>\nheader('HTTP\/1.1 301 Moved Permanently');<br \/>\nheader('Location:<span class=\"removed_link\" title=\"https:\/\/xptt.com'\">https:\/\/xptt.com'<\/span>.$URIRedirect);<br \/>\nexit();<br \/>\n}<\/p><\/blockquote>\n<p>\u7136\u540e\u628a\u4e24\u4e2axptt.com\u4fee\u6539\u6210\u4f60\u7684\u65b0\u7f51\u5740\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a301\u91cd\u5b9a\u5411\u65b9\u6cd5\u6700\u7b80\u5355\uff0c\u4e5f\u6700\u5bb9\u6613\uff01 \u4e8b\u60c5\u662f\u8fd9\u6837\u7684\uff0c\u4eca\u5929VPS\u7a81\u7136\u762b\u75ea\u4e86\uff0c\u8fd8\u597d\u524d\u4e24\u5929\u505a\u4e86\u5907\u4efd\uff0c\u90e8\u5206\u6570\u636e\u4e22\u5931\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":645960,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1148,733,177,953],"views":25352,"_links":{"self":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts\/645956"}],"collection":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/comments?post=645956"}],"version-history":[{"count":0,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts\/645956\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/media?parent=645956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/categories?post=645956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/tags?post=645956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}