{"id":34009,"date":"2025-07-28T10:50:39","date_gmt":"2025-07-28T02:50:39","guid":{"rendered":"https:\/\/www.kdjingpai.com\/?p=34009"},"modified":"2025-07-31T08:58:19","modified_gmt":"2025-07-31T00:58:19","slug":"wordpress-fanjiexia","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/ja\/wordpress-fanjiexia\/","title":{"rendered":"WordPress \u6cdb\u89e3\u6790\u5b50\u57df\u540d URL \u6539\u9020\u9ad8\u7ea7\u6307\u5357 (\u652f\u6301\u7ed1\u5b9a\u591a\u57df\u540d)"},"content":{"rendered":"<h3><strong>1. \u6838\u5fc3\u76ee\u6807\u4e0e\u9ad8\u7ea7\u529f\u80fd<\/strong><\/h3>\n<h4><strong>1.1. \u6838\u5fc3\u76ee\u6807<\/strong><\/h4>\n<p>\u5c06 WordPress \u7f51\u7ad9\u7684 URL \u7ed3\u6784\u4ece\u4f20\u7edf\u7684\u00a0<strong>\u76ee\u5f55\u5f62\u5f0f<\/strong>\uff0c\u4f18\u96c5\u5730\u8f6c\u53d8\u4e3a\u73b0\u4ee3\u7684\u00a0<strong>\u5b50\u57df\u540d\u5f62\u5f0f<\/strong>\uff0c\u5e76\u786e\u4fdd\u5bf9\u641c\u7d22\u5f15\u64ce\u53cb\u597d\u3002<\/p>\n<ul>\n<li><strong>\u8f6c\u6362\u524d URL \u7ed3\u6784<\/strong>:\u00a0<code>https:\/\/your-domain.com\/[\u524d\u7f00]\/[\u53d8\u91cf]\/<\/code><\/li>\n<li><strong>\u8f6c\u6362\u540e URL \u7ed3\u6784<\/strong>:\u00a0<code>https:\/\/[\u53d8\u91cf].your-domain.com\/<\/code><\/li>\n<\/ul>\n<h4><strong>1.2. \u9ad8\u7ea7\u529f\u80fd (\u65b0\u65b9\u6848\u6838\u5fc3)<\/strong><\/h4>\n<p>\u672c\u6307\u5357\u5c06\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301\u591a\u57df\u540d\u7684\u3001\u53ef\u7075\u6d3b\u5207\u6362\u7684URL\u7b56\u7565\u7cfb\u7edf\u3002<\/p>\n<ul>\n<li><strong>\u652f\u6301\u591a\u57df\u540d<\/strong>: \u53ef\u540c\u65f6\u4e3a\u591a\u4e2a\u4e3b\u57df\u540d\uff08\u5982\u00a0<code>aigcsoft.site<\/code>,\u00a0<code>tchepai.com<\/code>\uff09\u542f\u7528\u5b50\u57df\u540d\u6a21\u5f0f\u3002<\/li>\n<li><strong>URL \u7b56\u7565\u5f00\u5173<\/strong>: \u60a8\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u5f00\u5173\uff0c\u5728\u4ee5\u4e0b\u4e24\u79cd\u6a21\u5f0f\u95f4\u81ea\u7531\u5207\u6362\uff1a\n<ol>\n<li><strong>\u4e3b\u57df\u540d\u6a21\u5f0f (SEO \u6700\u4f73)<\/strong>: \u65e0\u8bba\u7528\u6237\u4ece\u54ea\u4e2a\u57df\u540d\u8bbf\u95ee\uff0c\u6700\u7ec8\u7684\u7f51\u5740\u548c\u9875\u9762\u5185\u94fe\u63a5\u90fd\u5c06\u5f3a\u5236\u7edf\u4e00\u5230\u60a8\u6307\u5b9a\u7684\u201c\u4e3b\u57df\u540d\u201d\u4e0a\uff0c\u4ee5\u96c6\u4e2d\u6743\u91cd\u3002<\/li>\n<li><strong>\u5f53\u524d\u57df\u540d\u6a21\u5f0f (\u7075\u6d3b\u5c55\u793a)<\/strong>: \u7f51\u7ad9\u4f1a\u4fdd\u6301\u7528\u6237\u5f53\u524d\u8bbf\u95ee\u7684\u57df\u540d\uff0c\u5e76\u5728\u8be5\u57df\u540d\u4e0b\u751f\u6210\u6240\u6709\u94fe\u63a5\uff0c\u9002\u7528\u4e8e\u591a\u54c1\u724c\u72ec\u7acb\u5c55\u793a\u7684\u573a\u666f\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h3><strong>2. \u51c6\u5907\u5de5\u4f5c\u4e0e\u6838\u5fc3\u6982\u5ff5<\/strong><\/h3>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u62e5\u6709\uff1a<\/p>\n<ul>\n<li>\u60a8\u6240\u6709\u76f8\u5173\u57df\u540d\u7684 DNS \u7ba1\u7406\u6743\u9650\u3002<\/li>\n<li>\u60a8\u7f51\u7ad9\u670d\u52a1\u5668\uff08\u4e3b\u673a\uff09\u7684\u540e\u53f0\u7ba1\u7406\u6743\u9650\uff08\u5982\u5b9d\u5854\u9762\u677f\u3001cPanel \u7b49\uff09\u3002<\/li>\n<\/ul>\n<p>\u6b64\u65b9\u6848\u4f9d\u8d56\u4e09\u5927\u6a21\u5757\u534f\u540c\u5de5\u4f5c\uff1a<\/p>\n<ul>\n<li><strong>DNS \u5c42<\/strong>: \u4f5c\u4e3a\u201c\u5730\u5740\u7c3f\u201d\uff0c\u5c06\u60a8<strong>\u6240\u6709\u57df\u540d<\/strong>\u7684\u5b50\u57df\u540d\u8bf7\u6c42\u6307\u5411\u60a8\u7684\u670d\u52a1\u5668\u3002<\/li>\n<li><strong>Web \u670d\u52a1\u5668\u5c42 (Nginx\/Apache)<\/strong>: \u4f5c\u4e3a\u201c\u4ea4\u901a\u6307\u6325\u201d\uff0c\u63a5\u6536\u6240\u6709\u8bf7\u6c42\uff0c\u5e76\u4e3a<strong>\u591a\u4e2a\u57df\u540d<\/strong>\u914d\u7f6e SSL \u548c\u8de8\u57df\u7b56\u7565\u3002<\/li>\n<li><strong>WordPress \u5e94\u7528\u5c42 (PHP)<\/strong>: \u4f5c\u4e3a\u201c\u5185\u5bb9\u5f15\u64ce\u201d\uff0c\u901a\u8fc7\u4ee3\u7801\u667a\u80fd\u8bc6\u522b\u8bf7\u6c42\u3001\u6839\u636e\u5f00\u5173\u7b56\u7565\u6539\u5199\u94fe\u63a5\u5e76\u6267\u884c\u91cd\u5b9a\u5411\u3002<\/li>\n<\/ul>\n<h3><strong>3. \u8be6\u7ec6\u914d\u7f6e\u6b65\u9aa4<\/strong><\/h3>\n<h4><strong>\u7b2c 1 \u6b65\uff1a\u4e3a\u6240\u6709\u57df\u540d\u914d\u7f6e DNS \u6cdb\u89e3\u6790<\/strong><\/h4>\n<p>\u6b64\u4e3a\u57fa\u7840\u3002\u60a8\u9700\u8981\u4e3a\u60a8\u8ba1\u5212\u4f7f\u7528\u7684<strong>\u6bcf\u4e00\u4e2a\u4e3b\u57df\u540d<\/strong>\u91cd\u590d\u6b64\u64cd\u4f5c\u3002<\/p>\n<ol>\n<li><strong>\u4f4d\u7f6e<\/strong>: \u6bcf\u4e2a\u57df\u540d\u6ce8\u518c\u5546\u7684 DNS \u7ba1\u7406\u9762\u677f\u3002<\/li>\n<li><strong>\u64cd\u4f5c<\/strong>: \u4e3a\u6bcf\u4e2a\u57df\u540d\u6dfb\u52a0\u4e00\u6761\u00a0<strong>A \u8bb0\u5f55<\/strong>\u3002\n<ul>\n<li><strong>\u4e3b\u673a\u8bb0\u5f55 (Host \/ Name)<\/strong>:\u00a0<code>*<\/code>\u00a0(\u661f\u53f7)<\/li>\n<li><strong>\u8bb0\u5f55\u7c7b\u578b (Type)<\/strong>:\u00a0<code>A<\/code><\/li>\n<li><strong>\u8bb0\u5f55\u503c (Value \/ Points to)<\/strong>:\u00a0<code>\u60a8\u670d\u52a1\u5668\u7684 IPv4 \u5730\u5740<\/code><\/li>\n<li><strong>\u793a\u4f8b<\/strong>: \u4e3a\u00a0<code>aigcsoft.site<\/code>\u00a0\u6dfb\u52a0\u4e00\u6761\u00a0<code>*<\/code>\u00a0\u8bb0\u5f55\uff0c\u518d\u4e3a\u00a0<code>tchepai.com<\/code>\u00a0\u6dfb\u52a0\u4e00\u6761\u00a0<code>*<\/code>\u00a0\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4><strong>\u7b2c 2 \u6b65\uff1a\u914d\u7f6e Web \u670d\u52a1\u5668 (\u4ee5\u5b9d\u5854\u9762\u677f\u4e3a\u4f8b)<\/strong><\/h4>\n<p><strong>2.1. \u6dfb\u52a0\u591a\u57df\u540d\u7ed1\u5b9a\u4e0e\u591a\u8bc1\u4e66\u914d\u7f6e<\/strong><\/p>\n<ol>\n<li><strong>\u521b\u5efa\/\u8bbe\u7f6e\u7ad9\u70b9<\/strong>:\n<ul>\n<li><strong>\u4f4d\u7f6e<\/strong>: \u5b9d\u5854\u9762\u677f -&gt; \u7f51\u7ad9\u7ba1\u7406\u3002<\/li>\n<li><strong>\u64cd\u4f5c<\/strong>: \u521b\u5efa\u4e00\u4e2a\u7ad9\u70b9\uff0c\u4e3b\u57df\u540d\u586b\u5199\u00a0<code>*.your-domain-1.com<\/code>\u3002\u7136\u540e\u8fdb\u5165\u8be5\u7ad9\u70b9\u7684\u201c\u57df\u540d\u7ba1\u7406\u201d\uff0c\u5c06\u60a8\u5176\u4ed6\u7684\u901a\u914d\u7b26\u57df\u540d\uff08\u5982\u00a0<code>*.your-domain-2.com<\/code>\uff09\u6dfb\u52a0\u8fdb\u53bb\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u914d\u7f6e\u591a\u5f20 SSL \u8bc1\u4e66 (\u5173\u952e\u6b65\u9aa4)<\/strong>:\n<ul>\n<li><strong>\u4f4d\u7f6e<\/strong>: \u7ad9\u70b9\u7684\u201c\u8bbe\u7f6e\u201d -&gt; \u201cSSL\u201d \u9009\u9879\u5361\u3002<\/li>\n<li><strong>\u4e3a\u7b2c\u4e00\u4e2a\u57df\u540d\u7533\u8bf7\u8bc1\u4e66<\/strong>:\n<ul>\n<li>\u9009\u62e9 &#8220;Let&#8217;s Encrypt&#8221;\uff0c\u9a8c\u8bc1\u65b9\u5f0f\u9009\u62e9\u201cDNS\u9a8c\u8bc1\u201d\u3002<\/li>\n<li>\u52fe\u9009\u00a0<code>your-domain-1.com<\/code>\u00a0\u548c\u00a0<code>*.your-domain-1.com<\/code>\uff0c\u6309\u63d0\u793a\u5b8c\u6210 DNS \u7684 TXT \u8bb0\u5f55\u9a8c\u8bc1\u5e76\u7533\u8bf7\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u4e3a\u7b2c\u4e8c\u4e2a\u57df\u540d\u7533\u8bf7\u8bc1\u4e66<\/strong>:\n<ul>\n<li>\u5728 SSL \u754c\u9762\uff0c\u70b9\u51fb\u5de6\u4e0a\u89d2\u7684<strong>\u8bc1\u4e66\u54c1\u724c\u4e0b\u62c9\u83dc\u5355<\/strong>\uff0c\u91cd\u65b0\u9009\u62e9\u201cLet&#8217;s Encrypt\u201d\u3002<\/li>\n<li>\u754c\u9762\u4f1a\u5237\u65b0\uff0c\u5141\u8bb8\u60a8\u53d1\u8d77\u4e00\u6b21<strong>\u65b0\u7684\u7533\u8bf7<\/strong>\u3002<\/li>\n<li>\u8fd9\u6b21<strong>\u53ea\u52fe\u9009<\/strong>\u00a0<code>your-domain-2.com<\/code>\u00a0\u548c\u00a0<code>*.your-domain-2.com<\/code>\uff0c\u518d\u6b21\u6309\u63d0\u793a\u5b8c\u6210\u65b0\u57df\u540d\u7684 DNS \u9a8c\u8bc1\u5e76\u7533\u8bf7\u3002<\/li>\n<li>\u5bf9\u6240\u6709\u57df\u540d\u91cd\u590d\u6b64\u64cd\u4f5c\u3002\u6700\u7ec8\uff0c\u60a8\u7684\u7ad9\u70b9\u4f1a\u540c\u65f6\u90e8\u7f72\u591a\u5f20\u8bc1\u4e66\uff0c\u670d\u52a1\u5668\u4f1a\u6839\u636e\u6765\u8bbf\u57df\u540d\u81ea\u52a8\u5339\u914d\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5f3a\u5236 HTTPS<\/strong>: \u6210\u529f\u90e8\u7f72\u6240\u6709\u8bc1\u4e66\u540e\uff0c\u52a1\u5fc5\u5f00\u542f\u201c\u5f3a\u5236 HTTPS\u201d\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>2.2. \u914d\u7f6e CORS \u8de8\u57df\u7b56\u7565 (\u89e3\u51b3\u56fe\u6807\/\u5b57\u4f53\u52a0\u8f7d\u95ee\u9898)<\/strong><br \/>\n\u6b64\u914d\u7f6e\u4e00\u6b21\u5373\u53ef\uff0c\u5bf9\u6240\u6709\u57df\u540d\u751f\u6548\u3002<\/p>\n<ol>\n<li><strong>\u4f4d\u7f6e<\/strong>: \u60a8\u7ad9\u70b9\u7684 Nginx \u6216 Apache \u914d\u7f6e\u6587\u4ef6\u3002<\/li>\n<li><strong>\u64cd\u4f5c<\/strong>:\n<ul>\n<li><strong>Nginx<\/strong>: \u5728\u00a0<code>server{}<\/code>\u00a0\u5757\u5185\u6dfb\u52a0\uff1a\n<pre><code># --- \u4e3a\u5b57\u4f53\u6587\u4ef6\u6dfb\u52a0 CORS \u8de8\u57df\u8bb8\u53ef ---\r\nlocation ~* \\.(eot|otf|ttf|woff|woff2)$ {\r\nadd_header 'Access-Control-Allow-Origin' '*' always;\r\n}\r\n<\/code><\/pre>\n<\/li>\n<li><strong>Apache<\/strong>: \u5728\u6839\u76ee\u5f55\u00a0<code>.htaccess<\/code>\u00a0\u6587\u4ef6\u4e2d\u6dfb\u52a0\uff1a\n<pre><code># --- \u4e3a\u5b57\u4f53\u6587\u4ef6\u6dfb\u52a0 CORS \u8de8\u57df\u8bb8\u53ef ---\r\n&lt;FilesMatch \"\\.(eot|otf|ttf|woff|woff2)$\"&gt;\r\nHeader set Access-Control-Allow-Origin \"*\"\r\n&lt;\/FilesMatch&gt;\r\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4fdd\u5b58\u5e76\u91cd\u8f7d\u670d\u52a1\u3002<\/li>\n<\/ol>\n<h4><strong>\u7b2c 3 \u6b65\uff1a\u4fee\u6539 WordPress \u6838\u5fc3\u6587\u4ef6<\/strong><\/h4>\n<p><strong>3.1. \u4fee\u6539\u00a0<code>wp-config.php<\/code>\u00a0\u6587\u4ef6 (\u4f4d\u4e8e\u7f51\u7ad9\u6839\u76ee\u5f55)<\/strong><br \/>\n\u6b64\u6587\u4ef6\u8d1f\u8d23\u8bc6\u522b\u6240\u6709\u6388\u6743\u57df\u540d\u7684\u5b50\u57df\u540d\u8bf7\u6c42\u3002<\/p>\n<p><strong>\u64cd\u4f5c<\/strong>: \u5728\u00a0<code>wp-config.php<\/code>\u00a0\u6587\u4ef6\u9876\u90e8 (<code>&lt;?php<\/code>\u00a0\u6807\u7b7e\u540e) \u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u5757\u3002<\/p>\n<pre><code>\/**\r\n* ===================================================================\r\n*               \u5b50\u57df\u540d\u6cdb\u89e3\u6790\u914d\u7f6e: \u5185\u90e8\u8bf7\u6c42\u91cd\u5199 (\u591a\u57df\u540d\u652f\u6301\u7248)\r\n* ===================================================================\r\n*\/\r\nif (isset($_SERVER['HTTP_HOST'])) {\r\n\/\/ --- \u8bf7\u5728\u8fd9\u91cc\u4fee\u6539\u4e3a\u60a8\u81ea\u5df1\u7684\u914d\u7f6e ---\r\n$SUBDOMAIN_CONFIG = [\r\n\/\/ \u5728\u6b64\u5217\u8868\u4e2d\u6dfb\u52a0\u6240\u6709\u60a8\u5e0c\u671b\u542f\u7528\u6b64\u529f\u80fd\u7684\u6839\u57df\u540d\r\n'allowed_main_domains' =&gt; [\r\n'aigcsoft.site',     \/\/ \u60a8\u7684\u7b2c\u4e00\u4e2a\u57df\u540d\r\n'tchepai.com',       \/\/ \u60a8\u7684\u7b2c\u4e8c\u4e2a\u57df\u540d\r\n],\r\n\/\/ \u8fd9\u662f\u60a8\u7684\u56fa\u5b9a\u76ee\u5f55\u524d\u7f00\r\n'url_prefix' =&gt; 'tool',\r\n];\r\n\/\/ --------------------------------\r\n$current_host = $_SERVER['HTTP_HOST'];\r\n$host_parts = explode('.', $current_host);\r\nif (count($host_parts) &gt;= 3 &amp;&amp; $host_parts[0] !== 'www') {\r\n$subdomain = $host_parts[0];\r\n$main_domain_candidate = implode('.', array_slice($host_parts, 1));\r\nif (in_array($main_domain_candidate, $SUBDOMAIN_CONFIG['allowed_main_domains'])) {\r\n$_SERVER['REQUEST_URI'] = '\/' . $SUBDOMAIN_CONFIG['url_prefix'] . '\/' . $subdomain . '\/';\r\n}\r\n}\r\n}\r\n<\/code><\/pre>\n<p><strong>3.2. \u4fee\u6539\u00a0<code>functions.php<\/code>\u00a0\u6587\u4ef6 (\u4f4d\u4e8e\u00a0<code>wp-content\/themes\/your-active-theme\/<\/code>)<\/strong><br \/>\n\u6b64\u6587\u4ef6\u662f URL \u7b56\u7565\u63a7\u5236\u4e2d\u5fc3\u3002<\/p>\n<p><strong>\u64cd\u4f5c<\/strong>: \u5728\u60a8\u4e3b\u9898\u7684\u00a0<code>functions.php<\/code>\u00a0\u6587\u4ef6\u672b\u5c3e\uff0c\u6dfb\u52a0\u4ee5\u4e0b<strong>\u5b8c\u6574\u7684\u4ee3\u7801\u5757<\/strong>\u3002<\/p>\n<pre><code>\/**\r\n* ===================================================================\r\n*            \u5b50\u57df\u540d\u6cdb\u89e3\u6790\u529f\u80fd\u5305: URL\u5904\u7406 &amp; SEO\u91cd\u5b9a\u5411 (\u5e26\u5f00\u5173\u7684\u591a\u57df\u540d\u652f\u6301\u7248)\r\n* ===================================================================\r\n*\/\r\n\/\/ --- \u8bf7\u5728\u8fd9\u91cc\u4fee\u6539\u4e3a\u60a8\u81ea\u5df1\u7684\u914d\u7f6e ---\r\n$MY_APP_CONFIG = [\r\n\/\/ [\u91cd\u8981!] \u5b9a\u4e49\u60a8\u7684\u201c\u5b98\u65b9\u201d\u4e3b\u57df\u540d\u3002\r\n'canonical_domain' =&gt; 'aigcsoft.site',\r\n\/\/ \u6240\u6709\u6388\u6743\u7684\u57df\u540d (\u4e0e wp-config.php \u4e2d\u4fdd\u6301\u4e00\u81f4)\r\n'allowed_main_domains' =&gt; [\r\n'aigcsoft.site',\r\n'tchepai.com',\r\n],\r\n\/\/ \u60a8\u7684\u56fa\u5b9a\u76ee\u5f55\u524d\u7f00\r\n'url_prefix'  =&gt; 'tool',\r\n\/**\r\n* [\u603b\u5f00\u5173] \u662f\u5426\u5f3a\u5236\u4f7f\u7528\u4e3b\u57df\u540d (Canonical Domain)\r\n* - \u8bbe\u7f6e\u4e3a true:  \u3010SEO \u6700\u4f73\u5b9e\u8df5\u3011\u65e0\u8bba\u7528\u6237\u4ece\u54ea\u4e2a\u57df\u540d\u8bbf\u95ee\uff0c\u6700\u7ec8\u5730\u5740\u548c\u9875\u9762\u5185\u94fe\u63a5\u90fd\u4f1a\u7edf\u4e00\u5230 'canonical_domain'\u3002\r\n* - \u8bbe\u7f6e\u4e3a false: \u3010\u7075\u6d3b\u5c55\u793a\u6a21\u5f0f\u3011\u7f51\u5740\u4f1a\u663e\u793a\u7528\u6237\u5f53\u524d\u8bbf\u95ee\u7684\u57df\u540d\uff0c\u5b9e\u73b0\u591a\u54c1\u724c\u72ec\u7acb\u5c55\u793a\u3002\r\n*\/\r\n'force_canonical_domain' =&gt; true, \/\/ \u5728\u8fd9\u91cc\u5207\u6362 true \u6216 false\r\n];\r\n\/\/ --------------------------------\r\n\/\/ \u529f\u80fd 1: \u7981\u7528 WordPress \u89c4\u8303\u94fe\u63a5\u91cd\u5b9a\u5411 (\u57fa\u77f3)\r\nremove_filter('template_redirect', 'redirect_canonical');\r\n\/\/ \u529f\u80fd 2: \u52a8\u6001\u91cd\u5199\u7f51\u7ad9\u5185\u6240\u6709\u76f8\u5173\u94fe\u63a5 (\u5df2\u5347\u7ea7)\r\nfunction my_theme_rewrite_internal_links($permalink, $post) {\r\nglobal $MY_APP_CONFIG;\r\n$prefix_to_check = '\/' . $MY_APP_CONFIG['url_prefix'] . '\/';\r\nif (strpos($permalink, $prefix_to_check) !== false) {\r\n$target_domain = $MY_APP_CONFIG['canonical_domain'];\r\nif (!$MY_APP_CONFIG['force_canonical_domain']) {\r\n$current_main_domain = implode('.', array_slice(explode('.', $_SERVER['HTTP_HOST']), -2));\r\nif (in_array($current_main_domain, $MY_APP_CONFIG['allowed_main_domains'])) {\r\n$target_domain = $current_main_domain;\r\n}\r\n}\r\nreturn 'https:\/\/' . $post-&gt;post_name . '.' . $target_domain . '\/';\r\n}\r\nreturn $permalink;\r\n}\r\nadd_filter('post_link', 'my_theme_rewrite_internal_links', 20, 2);\r\nadd_filter('post_type_link', 'my_theme_rewrite_internal_links', 20, 2);\r\n\/\/ \u529f\u80fd 3: \u4e3a\u65e7\u94fe\u63a5 (\/prefix\/slug\/) \u8bbe\u7f6e 301 \u6c38\u4e45\u91cd\u5b9a\u5411 (\u5df2\u5347\u7ea7)\r\nfunction my_theme_redirect_old_urls() {\r\nglobal $MY_APP_CONFIG;\r\n$prefix_to_check = '\/' . $MY_APP_CONFIG['url_prefix'] . '\/';\r\nif (in_array($_SERVER['HTTP_HOST'], $MY_APP_CONFIG['allowed_main_domains']) &amp;&amp; strpos($_SERVER['REQUEST_URI'], $prefix_to_check) === 0) {\r\n$slug = trim(str_replace($prefix_to_check, '', $_SERVER['REQUEST_URI']), '\/');\r\nif (!empty($slug)) {\r\n$target_domain = $MY_APP_CONFIG['force_canonical_domain'] ? $MY_APP_CONFIG['canonical_domain'] : $_SERVER['HTTP_HOST'];\r\nwp_redirect('https:\/\/' . $slug . '.' . $target_domain . '\/', 301);\r\nexit;\r\n}\r\n}\r\n}\r\nadd_action('template_redirect', 'my_theme_redirect_old_urls');\r\n\/\/ \u529f\u80fd 4: [\u65b0\u589e] \u5f53\u5f00\u5173\u5f00\u542f\u65f6\uff0c\u5c06\u975e\u4e3b\u57df\u540d\u8bbf\u95ee\u91cd\u5b9a\u5411\u5230\u4e3b\u57df\u540d\r\nfunction my_theme_redirect_to_canonical_domain() {\r\nglobal $MY_APP_CONFIG;\r\nif (!$MY_APP_CONFIG['force_canonical_domain']) return;\r\n$current_host = $_SERVER['HTTP_HOST'];\r\n$host_parts = explode('.', $current_host);\r\nif (count($host_parts) &gt;= 3 &amp;&amp; $host_parts[0] !== 'www') {\r\n$subdomain = $host_parts[0];\r\n$current_main_domain = implode('.', array_slice($host_parts, 1));\r\nif (in_array($current_main_domain, $MY_APP_CONFIG['allowed_main_domains']) &amp;&amp; $current_main_domain !== $MY_APP_CONFIG['canonical_domain']) {\r\nwp_redirect('https:\/\/' . $subdomain . '.' . $MY_APP_CONFIG['canonical_domain'] . '\/', 301);\r\nexit;\r\n}\r\n}\r\n}\r\nadd_action('template_redirect', 'my_theme_redirect_to_canonical_domain', 5);\r\n<\/code><\/pre>\n<h3><strong>4. \u6700\u7ec8\u9a8c\u8bc1\u4e0e\u6545\u969c\u6392\u67e5<\/strong><\/h3>\n<ol>\n<li><strong>\u6e05\u7406\u7f13\u5b58<\/strong>: \u5b8c\u6210\u4fee\u6539\u540e\uff0c<strong>\u5fc5\u987b<\/strong>\u6e05\u7406\u6240\u6709\u7f13\u5b58\uff08\u63d2\u4ef6\u3001CDN\u3001\u670d\u52a1\u5668\u3001\u6d4f\u89c8\u5668\uff09\u3002\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528<strong>\u65e0\u75d5\u6a21\u5f0f<\/strong>\u6d4b\u8bd5\u3002<\/li>\n<li><strong>\u5207\u6362\u5f00\u5173<\/strong>: \u5728\u00a0<code>functions.php<\/code>\u00a0\u4e2d\u4fee\u6539\u00a0<code>'force_canonical_domain'<\/code>\u00a0\u7684\u503c (<code>true<\/code>\/<code>false<\/code>) \u6765\u6d4b\u8bd5\u4e0d\u540c\u6a21\u5f0f\u3002<\/li>\n<\/ol>\n<h4><strong>4.1. \u9a8c\u8bc1\u65b9\u6cd5\uff1a\u5f53\u5f00\u5173\u4e3a\u00a0<code>true<\/code>\u00a0(\u4e3b\u57df\u540d\u6a21\u5f0f)<\/strong><\/h4>\n<ul>\n<li><strong>\u6d4b\u8bd5\u8df3\u8f6c<\/strong>: \u5728\u6d4f\u89c8\u5668\u5730\u5740\u680f\u8f93\u5165\u00a0<code>[\u53d8\u91cf].your-domain-2.com<\/code>\u3002\u6309\u56de\u8f66\u540e\uff0c\u5730\u5740\u680f\u5e94<strong>\u7acb\u5373\u8df3\u8f6c<\/strong>\u5230\u00a0<code>[\u53d8\u91cf].your-domain-1.com<\/code>\u00a0(\u60a8\u7684\u4e3b\u57df\u540d)\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u94fe\u63a5<\/strong>: \u8bbf\u95ee\u4efb\u610f\u9875\u9762\uff0c\u53f3\u952e\u68c0\u67e5\u6240\u6709\u5185\u90e8\u94fe\u63a5\uff0c\u5b83\u4eec\u7684\u00a0<code>href<\/code>\u00a0\u5c5e\u6027<strong>\u5fc5\u987b\u5168\u90e8<\/strong>\u6307\u5411\u60a8\u7684\u4e3b\u57df\u540d (<code>...your-domain-1.com<\/code>)\u3002<\/li>\n<\/ul>\n<h4><strong>4.2. \u9a8c\u8bc1\u65b9\u6cd5\uff1a\u5f53\u5f00\u5173\u4e3a\u00a0<code>false<\/code>\u00a0(\u5f53\u524d\u57df\u540d\u6a21\u5f0f)<\/strong><\/h4>\n<ul>\n<li><strong>\u6d4b\u8bd5\u4fdd\u6301<\/strong>: \u8bbf\u95ee\u00a0<code>[\u53d8\u91cf].your-domain-2.com<\/code>\uff0c\u5730\u5740\u680f\u5e94<strong>\u4fdd\u6301\u4e0d\u53d8<\/strong>\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u94fe\u63a5<\/strong>: \u5728\u00a0<code>[\u53d8\u91cf].your-domain-2.com<\/code>\u00a0\u9875\u9762\u4e0a\uff0c\u53f3\u952e\u68c0\u67e5\u6240\u6709\u5185\u90e8\u94fe\u63a5\uff0c\u5b83\u4eec\u7684\u00a0<code>href<\/code>\u00a0\u5c5e\u6027\u5e94\u6307\u5411\u5f53\u524d\u57df\u540d (<code>...your-domain-2.com<\/code>)\u3002<\/li>\n<li><strong>\u4ea4\u53c9\u6d4b\u8bd5<\/strong>: \u65b0\u5f00\u6807\u7b7e\u9875\u8bbf\u95ee\u00a0<code>[\u53d8\u91cf].your-domain-1.com<\/code>\uff0c\u8be5\u9875\u9762\u7684\u94fe\u63a5\u5219\u5e94\u6307\u5411\u00a0<code>...your-domain-1.com<\/code>\u3002<\/li>\n<\/ul>\n<h4><strong>4.3. \u5e38\u89c1\u95ee\u9898\u6392\u67e5<\/strong><\/h4>\n<ul>\n<li><strong>\u65e0\u9650\u91cd\u5b9a\u5411<\/strong>: \u786e\u4fdd\u00a0<code>remove_filter('template_redirect', 'redirect_canonical');<\/code>\u00a0\u5b58\u5728\u4e14\u672a\u88ab\u6ce8\u91ca\u3002<\/li>\n<li><strong>\u8bc1\u4e66\u9519\u8bef\/\u4e0d\u5b89\u5168<\/strong>: \u68c0\u67e5\u7b2c 2.1 \u6b65\uff0c\u786e\u4fdd\u5df2\u4e3a\u6240\u6709\u57df\u540d\u6210\u529f\u7533\u8bf7\u5e76\u90e8\u7f72\u4e86\u72ec\u7acb\u7684 SSL \u8bc1\u4e66\u3002<\/li>\n<li><strong>\u56fe\u6807\/\u5b57\u4f53\u4e22\u5931<\/strong>: \u68c0\u67e5\u7b2c 2.2 \u6b65\u7684 CORS \u8de8\u57df\u914d\u7f6e\u3002<\/li>\n<li><strong>\u94fe\u63a5\u6216\u8df3\u8f6c\u884c\u4e3a\u4e0d\u7b26\u5408\u9884\u671f<\/strong>: \u68c0\u67e5\u00a0<code>functions.php<\/code>\u00a0\u4e2d\u5f00\u5173\u7684\u503c\u662f\u5426\u6b63\u786e\uff0c\u5e76<strong>\u5f7b\u5e95\u6e05\u7406\u7f13\u5b58<\/strong>\u3002<\/li>\n<li><strong>\u7f51\u7ad9\u767d\u5c4f\/500\u9519\u8bef<\/strong>: \u68c0\u67e5\u00a0<code>wp-config.php<\/code>\u00a0\u6216\u00a0<code>functions.php<\/code>\u00a0\u4e2d\u662f\u5426\u6709 PHP \u8bed\u6cd5\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p>\u8bf7\u59a5\u5584\u4fdd\u7ba1\u6b64\u4efd\u9ad8\u7ea7\u6307\u5357\uff0c\u5b83\u5c06\u662f\u60a8\u672a\u6765\u8fdb\u884c\u670d\u52a1\u5668\u8fc1\u79fb\u3001\u4e3b\u9898\u5347\u7ea7\u6216\u4e3a\u65b0\u9879\u76ee\u5b9e\u65bd\u76f8\u540c\u7b56\u7565\u65f6\u7684\u5b9d\u8d35\u8d22\u5bcc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u6838\u5fc3\u76ee\u6807\u4e0e\u9ad8\u7ea7\u529f\u80fd 1.1. \u6838\u5fc3\u76ee\u6807 \u5c06 WordPress \u7f51\u7ad9\u7684 URL \u7ed3\u6784\u4ece\u4f20\u7edf\u7684\u00a0\u76ee\u5f55\u5f62\u5f0f\uff0c\u4f18\u96c5\u5730\u8f6c\u53d8\u4e3a\u73b0\u4ee3\u7684\u00a0\u5b50\u57df\u540d\u5f62\u5f0f\uff0c\u5e76\u786e\u4fdd\u5bf9\u641c\u7d22\u5f15\u64ce\u53cb\u597d\u3002 \u8f6c\u6362\u524d URL \u7ed3\u6784:\u00a0https:\/\/your-domain.com\/[&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-34009","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/34009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/comments?post=34009"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/34009\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/media?parent=34009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/categories?post=34009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/tags?post=34009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}