{"id":49526,"date":"2024-10-08T05:21:15","date_gmt":"2024-10-07T21:21:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49526\/"},"modified":"2024-10-08T05:21:15","modified_gmt":"2024-10-07T21:21:15","slug":"%e6%b2%92%e6%9c%89-isapi-rewrite-full-%e7%85%a7%e6%a8%a3%e7%8e%a9%e5%a4%9a%e7%ab%99%e9%bb%9e%e5%81%bd%e9%9d%9c%e6%85%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49526\/","title":{"rendered":"\u6c92\u6709 ISAPI Rewrite FULL \u7167\u6a23\u73a9\u591a\u7ad9\u9ede\u507d\u975c\u614b"},"content":{"rendered":"<h1 id=\"%e6%b2%92%e6%9c%89-isapi-rewrite-full-%e7%85%a7%e6%a8%a3%e7%8e%a9%e5%a4%9a%e7%ab%99%e9%bb%9e%e5%81%bd%e9%9d%9c%e6%85%8b-gGsWdINVgO\">\u6c92\u6709 ISAPI Rewrite FULL \u7167\u6a23\u73a9\u591a\u7ad9\u9ede\u507d\u975c\u614b<\/h1>\n<p>\u5728\u7db2\u9801\u958b\u767c\u4e2d\uff0cURL \u7684\u7d50\u69cb\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u548c\u641c\u7d22\u5f15\u64ce\u512a\u5316\uff08SEO\uff09\u81f3\u95dc\u91cd\u8981\u3002\u8a31\u591a\u958b\u767c\u8005\u6703\u4f7f\u7528 ISAPI Rewrite \u4f86\u5be6\u73fe URL \u7684\u91cd\u5beb\uff0c\u5f9e\u800c\u4f7f\u5176\u66f4\u5177\u53ef\u8b80\u6027\u548c\u53cb\u597d\u6027\u3002\u7136\u800c\uff0c\u5c0d\u65bc\u4e00\u4e9b\u4f7f\u7528 Windows \u4f3a\u670d\u5668\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u53ef\u80fd\u6703\u9047\u5230\u6c92\u6709 ISAPI Rewrite FULL \u7684\u60c5\u6cc1\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\u5be6\u73fe\u591a\u7ad9\u9ede\u7684\u507d\u975c\u614b\u6548\u679c\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%81%bd%e9%9d%9c%e6%85%8b%ef%bc%9f-gGsWdINVgO\">\u4ec0\u9ebc\u662f\u507d\u975c\u614b\uff1f<\/h2>\n<p>\u507d\u975c\u614b\u662f\u6307\u5c07\u52d5\u614b\u751f\u6210\u7684 URL \u8f49\u63db\u70ba\u975c\u614b URL \u7684\u904e\u7a0b\u3002\u9019\u6a23\u7684 URL \u901a\u5e38\u66f4\u77ed\u3001\u66f4\u6613\u65bc\u8a18\u61b6\uff0c\u4e26\u4e14\u5c0d\u65bc\u641c\u7d22\u5f15\u64ce\u4f86\u8aaa\u66f4\u5177\u5438\u5f15\u529b\u3002\u4f8b\u5982\uff0c\u5c07\u4e00\u500b\u52d5\u614b URL <code>http:\/\/example.com\/index.php?id=123<\/code> \u8f49\u63db\u70ba <code>http:\/\/example.com\/products\/123<\/code>\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%81%bd%e9%9d%9c%e6%85%8b%ef%bc%9f-gGsWdINVgO\">\u70ba\u4ec0\u9ebc\u9700\u8981\u507d\u975c\u614b\uff1f<\/h2>\n<ul>\n<li><strong>\u63d0\u5347 SEO\uff1a<\/strong>\u641c\u7d22\u5f15\u64ce\u66f4\u5bb9\u6613\u7d22\u5f15\u975c\u614b URL\uff0c\u9019\u6709\u52a9\u65bc\u63d0\u9ad8\u7db2\u7ad9\u7684\u6392\u540d\u3002<\/li>\n<li><strong>\u6539\u5584\u7528\u6236\u9ad4\u9a57\uff1a<\/strong>\u7c21\u6f54\u7684 URL \u66f4\u5bb9\u6613\u88ab\u7528\u6236\u8a18\u4f4f\u548c\u5206\u4eab\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u4f3a\u670d\u5668\u8ca0\u64d4\uff1a<\/strong>\u975c\u614b URL \u901a\u5e38\u80fd\u5920\u6e1b\u5c11\u4f3a\u670d\u5668\u7684\u8655\u7406\u6642\u9593\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9c%a8%e6%b2%92%e6%9c%89-isapi-rewrite-%e7%9a%84%e6%83%85%e6%b3%81%e4%b8%8b%e5%af%a6%e7%8f%be%e5%81%bd%e9%9d%9c%e6%85%8b-gGsWdINVgO\">\u5728\u6c92\u6709 ISAPI Rewrite \u7684\u60c5\u6cc1\u4e0b\u5be6\u73fe\u507d\u975c\u614b<\/h2>\n<p>\u5373\u4f7f\u6c92\u6709 ISAPI Rewrite FULL\uff0c\u4ecd\u7136\u53ef\u4ee5\u901a\u904e\u5176\u4ed6\u65b9\u6cd5\u4f86\u5be6\u73fe\u507d\u975c\u614b\u6548\u679c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u53ef\u884c\u7684\u65b9\u6848\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-url-%e9%87%8d%e5%af%ab%e6%a8%a1%e7%b5%84-gGsWdINVgO\">1. \u4f7f\u7528 URL \u91cd\u5beb\u6a21\u7d44<\/h3>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f IIS \u4f3a\u670d\u5668\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u5167\u5efa\u7684 URL \u91cd\u5beb\u6a21\u7d44\u3002\u9019\u500b\u6a21\u7d44\u5141\u8a31\u60a8\u5275\u5efa\u898f\u5247\u4f86\u91cd\u5beb URL\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>\n\n    \n    \n\n<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07 <code>http:\/\/example.com\/products\/123<\/code> \u8f49\u63db\u70ba <code>http:\/\/example.com\/index.php?id=123<\/code>\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-php-%e9%80%b2%e8%a1%8c-url-%e8%99%95%e7%90%86-gGsWdINVgO\">2. \u4f7f\u7528 PHP \u9032\u884c URL \u8655\u7406<\/h3>\n<p>\u5982\u679c\u60a8\u7121\u6cd5\u4f7f\u7528 URL \u91cd\u5beb\u6a21\u7d44\uff0c\u9084\u53ef\u4ee5\u5728 PHP \u4e2d\u624b\u52d5\u8655\u7406 URL\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>$_SERVER['REQUEST_URI']<\/code> \u4f86\u7372\u53d6\u7576\u524d\u8acb\u6c42\u7684 URL\uff0c\u7136\u5f8c\u6839\u64da\u9700\u8981\u9032\u884c\u8655\u7406\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>\n$request_uri = $_SERVER['REQUEST_URI'];\nif (preg_match('\/^\/products\/([0-9]+)$\/', $request_uri, $matches)) {\n    $id = $matches[1];\n    \/\/ \u6839\u64da ID \u52a0\u8f09\u7522\u54c1\n}\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-htaccess-%e6%96%87%e4%bb%b6-gGsWdINVgO\">3. \u4f7f\u7528 .htaccess \u6587\u4ef6<\/h3>\n<p>\u5982\u679c\u60a8\u7684\u4f3a\u670d\u5668\u652f\u6301 .htaccess \u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u5728\u8a72\u6587\u4ef6\u4e2d\u6dfb\u52a0\u91cd\u5beb\u898f\u5247\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>\nRewriteEngine On\nRewriteRule ^products\/([0-9]+)$ index.php?id=$1 [L]\n<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u7576\u7528\u6236\u8a2a\u554f <code>http:\/\/example.com\/products\/123<\/code> \u6642\uff0c\u4f3a\u670d\u5668\u6703\u81ea\u52d5\u5c07\u8acb\u6c42\u91cd\u5beb\u70ba <code>index.php?id=123<\/code>\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-gGsWdINVgO\">\u7d50\u8ad6<\/h2>\n<p>\u96d6\u7136\u6c92\u6709 ISAPI Rewrite FULL \u53ef\u80fd\u6703\u8b93\u591a\u7ad9\u9ede\u7684\u507d\u975c\u614b\u5be6\u73fe\u8b8a\u5f97\u8907\u96dc\uff0c\u4f46\u901a\u904e\u4f7f\u7528 IIS \u7684 URL \u91cd\u5beb\u6a21\u7d44\u3001PHP \u8655\u7406\u6216 .htaccess \u6587\u4ef6\uff0c\u4ecd\u7136\u53ef\u4ee5\u9054\u5230\u76f8\u4f3c\u7684\u6548\u679c\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u5347\u7db2\u7ad9\u7684 SEO \u8868\u73fe\uff0c\u9084\u80fd\u6539\u5584\u7528\u6236\u9ad4\u9a57\uff0c\u8b93\u7db2\u7ad9\u66f4\u5177\u5438\u5f15\u529b\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5728\u6c92\u6709 ISAPI Rewrite \u7684\u60c5\u6cc1\u4e0b\uff0c\u5be6\u73fe\u591a\u7ad9\u9ede\u7684\u507d\u975c\u614b\u6548\u679c\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207SEO\u512a\u5316\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-49526","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=49526"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49526\/revisions"}],"predecessor-version":[{"id":49527,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49526\/revisions\/49527"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}