{"id":48,"date":"2016-04-20T09:06:22","date_gmt":"2016-04-20T09:06:22","guid":{"rendered":"http:\/\/120.27.50.22\/wordpress\/?p=48"},"modified":"2016-04-20T09:06:22","modified_gmt":"2016-04-20T09:06:22","slug":"linux%e4%b8%8b%e5%bc%80%e5%90%afapache%e7%9a%84url%e9%87%8d%e5%86%99","status":"publish","type":"post","link":"http:\/\/www.homconnect.cn\/?p=48","title":{"rendered":"linux\u4e0b\u5f00\u542fapache\u7684url\u91cd\u5199"},"content":{"rendered":"<p>Apache 2.x \u4e2dURL\u91cd\u5199\uff0c\u662f\u901a\u8fc7mod_rewrite.so \u6765\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u60a8\u8981\u67e5\u770b\u60a8\u7684Apache \u662f\u5426\u5df2\u7ecf\u88ab\u7f16\u8bd1\u8fdb\u53bb\u8fd9\u4e2a\u6a21\u5757\u4e86\uff0c\u5e76\u4e14\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6httpd.conf \u4e2d\u5df2\u7ecf\u8c03\u7528\u4e86\u8fd9\u4e2a\u6a21\u5757\u3002<\/p>\n<p><strong>Linux\u5f00\u542furl\u91cd\u5199\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><\/strong>1\u3001\u6253\u5f00 apache \u91cchttpd.conf\uff08\u901a\u5e38\u662f\u5728\/etc\/httpd\/conf\u76ee\u5f55\u91cc\uff09<\/p>\n<p>2\u3001\u627e\u5230 #LoadModule rewrite_module modules\/mod_rewrite.so \u53bb\u6389\u524d\u9762\u7684#<\/p>\n<p>3\u3001\u627e\u5230 AllowOverride None \u6539\u6210 AllowOverride All , \u6709\u4e24\u4e2a\u5168\u90e8\u6539\u6389<\/p>\n<p>\u6ce8\uff1aAllowOverride \u7684\u53c2\u6570\u8bbe\u7f6e\u4e3aALL\uff0c\u8868\u793a\u6574\u53f0\u670d\u52a1\u5668\u4e0a\u90fd\u652f\u6301URL\u89c4\u5219\u91cd\u5199\u3002Apache \u670d\u52a1\u5668\u8981\u8bfb\u6bcf\u4e2a\u7f51\u7ad9\u4e0b\u76ee\u5f55\u4e0b\u7684 .htaccess \u6587\u4ef6\u3002\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u8fd9\u4e2a\u6587\u6863\u6ca1\u6709\u5b9a\u4e49\u4efb\u4f55\u5173\u4e8eURL\u91cd\u5199\u7684\u89c4\u5219\u5c31\u4e0d\u4f1a\u6709\u4efb\u4f55\u6548\u679c\u3002<\/p>\n<p>\u91cd\u542fapache (\u7528\u547d\u4ee4\uff1aservice httpd restart)\u3002<\/p>\n<p><strong>Apache\u5f00\u542fURL\u91cd\u5199\u529f\u80fd\u65b9\u6cd5\u8be6\u7ec6\u7bc7<\/p>\n<p><\/strong>1\u3001\u5173\u4e8erewrite\u6a21\u5757\u7684\u8c03\u7528\uff1a<br \/>\nApache 2.x \u4e2dURL\u91cd\u5199\uff0c\u662f\u901a\u8fc7mod_rewrite.so \u6765\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u60a8\u8981\u67e5\u770b\u60a8\u7684Apache \u662f\u5426\u5df2\u7ecf\u88ab\u7f16\u8bd1\u8fdb\u53bb\u8fd9\u4e2a\u6a21\u5757\u4e86\uff0c\u5e76\u4e14\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6httpd.conf \u4e2d\u5df2\u7ecf\u8c03\u7528\u4e86\u8fd9\u4e2a\u6a21\u5757\u3002\u5728\u5927\u591a\u6570\u4e3b\u6d41\u53d1\u884c\u7248\u4e2d\uff0cApache 2.x \u662f\u628arewrite\u6a21\u5757\u5df2\u7ecf\u7f16\u5165\u8fdb\u53bb\u4e86\u3002\u6bd4\u5982\u6211\u7528\u7684\u662fSlackware\u3002Apache 2.x\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u653e\u5728 \/etc\/httpd \u76ee\u5f55\u4e0b\u3002<\/p>\n<p>\u5728 httpd.conf \u4e2d\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u4e00\u884c\uff0c\u662f\u6709\u5173rewrite\u6a21\u5757\u7684\uff0c\u6a21\u5757\u540d\u662f mod_rewrite.so \u3002<\/p>\n<p>LoadModule rewrite_module lib\/httpd\/modules\/mod_rewrite.so<br \/>\n\u6216<br \/>\nLoadModule rewrite_module lib\/apache2\/modules\/mod_rewrite.so \u5982\u679c\u524d\u9762\u6709#\u53f7\uff0c\u60a8\u8981\u53bb\u6389\u3002\u5bf9\u4e8e\u5927\u591a\u6570\u53d1\u884c\u7248\u6765\u8bf4\uff0cApache 2\u7684\u6a21\u5757\u4e00\u822c\u662f\u4f4d\u4e8e\u5982\u4e0b\u7684\u4e24\u4e2a\u4f4d\u7f6e<\/p>\n<p>\/usr\/lib\/apache2\/modules<\/p>\n<p>\u6216<br \/>\n\/usr\/lib\/httpd\/modules \u5982\u679c\u5728httpd\u4e2d\u6253\u5f00\u8c03\u7528rewrite_module\u7684\u8bbe\u7f6e\uff0c\u67e5\u770b\u4e00\u4e0b\u662f\u4e0d\u662f\u80fd\u8c03\u7528\u4e86\uff0c\u8981\u901a\u8fc7 httpd -M\u7684\u53c2\u6570\u6765\u67e5\u770b\uff1b<\/p>\n<p>#\/usr\/sbin\/httpd -M<\/p>\n<p>\u5982\u679c\u53d1\u73b0\u6709\u5982\u4e0b\u4e00\u884c\uff0c\u8bf4\u660e\u6a21\u5757\u5df2\u7ecf\u80fd\u88ab\u8c03\u7528\u4e86<\/p>\n<p>rewrite_module (shared)<\/p>\n<p>2\u3001\u8bbe\u7f6eDocumentRoot\u7684Directory\uff1a<\/p>\n<p>\u5728Apache 2.x \u4e2d\uff0c\u6211\u4eec\u4f1a\u770b\u5230 DocumentRoot\u8bbe\u7f6e\u7684\u4e00\u884c\u3002\u8fd9\u884c\u5c31\u662f\u5b58\u653e\u7f51\u9875\u7a0b\u5e8f\u7684\u5730\u65b9\u3002\u6bd4\u5982LinuxSir.Org \u5b58\u653e\u5728 \/opt\/www \u76ee\u5f55\u4e2d\u3002\u90a3\u4e48\u6211\u4eec\u5c31\u8981\u8bbe\u7f6e DocumentRoot\u4e3a\u5982\u4e0b\u7684\u3002<\/p>\n<p>DocumentRoot &#8220;\/opt\/www&#8221; \u7136\u540e\u6211\u4eec\u518d\u8fd8\u8981\u5bf9 DocumentRoot\u505a\u9488\u5bf9\u6027\u7684\u884c\u4e3a\u8bbe\u7f6e\u3002\u5728\u4e00\u822c\u7684\u60c5\u51b5\u4e0b\uff0chttpd.conf \u4f1a\u7ed9\u4e00\u4e2a\u9ed8\u8ba4\u7684\u3002\u5982\u679c\u4f60\u8981\u6539 DocumentRoot\u7684\u8def\u5f84\uff0c\u540c\u65f6\u4e5f\u8981\u6539\u9488\u5bf9DocumentRoot\u7684Directory\u7684\u8bbe\u7f6e\uff0c\u4e5f\u5c31\u662f<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u628aDocumentRoot\u7684\u8def\u5f84\u6539\u4e3a\u4e86 &#8220;\/opt\/www&#8221;\uff0c\u90a3\u6211\u4eec\u4e5f\u8981\u628aDirectory\u505a\u9488\u5bf9\u6027\u7684\u884c\u4e3a\u8bbe\u7f6e\u4e5f\u8981\u6539\u6210\u8fd9\u4e2a\u8def\u5f84\u3002<\/p>\n<p>Options FollowSymLinks<br \/>\n#AllowOverride None \u6ce8\uff1a\u628a\u8fd9\u884c\u524d\u9762\u52a0#\u53f7\uff0c\u7136\u540e\u52a0\u4e0b\u9762\u7684\u4e00\u884c \uff0c\u4e5f\u5c31\u662f AllowOverride ALL<br \/>\nAllowOverride ALL<br \/>\nOrder allow,deny<br \/>\nAllow from all<br \/>\n\u6211\u4eec\u628aAllowOverride \u7684\u53c2\u6570\u8bbe\u7f6e\u4e3aALL\uff0c\u8868\u793a\u6574\u53f0\u670d\u52a1\u5668\u4e0a\u7684\uff0c\u90fd\u652f\u6301URL\u89c4\u5219\u91cd\u5199\u3002Apache \u670d\u52a1\u5668\u8981\u8bfb\u6bcf\u4e2a\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u7684 .htaccess \u6587\u4ef6\u3002\u5982\u679c\u6ca1\u6709\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6216\u8005\u8fd9\u4e2a\u6587\u6863\u6ca1\u6709\u5b9a\u4e49\u4efb\u4f55\u5173\u4e8eURL\u91cd\u5199\u7684\u89c4\u5219\uff0c\u5219\u4e0d\u4f1a\u6709\u4efb\u4f55\u6548\u679c\u3002\u5728\u4e00\u822c\u7684\u60c5\u51b5\u4e0b\uff0c\u6210\u719f\u7684Web \u670d\u52a1\u5668\u5e94\u7528\u5957\u4ef6\uff0c\u90fd\u652f\u6301URL\u91cd\u5199\u7684\uff0c\u6bd4\u5982drupal\u548cjoomla \u3002\u5f53\u6211\u4eec\u7528\u8fd9\u4e9b\u7a0b\u5e8f\u65f6\uff0c\u4f1a\u53d1\u73b0\u5728\u5b89\u88c5\u5305\u4e2d\u6709 .htaccess\u4e2d\u6709\u8fd9\u4e2a\u6587\u4ef6\u3002\u6211\u4eec\u628aApache\u914d\u7f6e\u597d\u540e\uff0c\u53ea\u662f\u9700\u8981\u5728\u8fd9\u4e9b\u7a0b\u5e8f\u7684\u540e\u53f0\u6253\u5f00\u6b64\u529f\u80fd\u5c31\u884c\u4e86\u3002<\/p>\n<p>3\u3001\u91cd\u542fhttpd\u670d\u52a1\u5668\uff1a<\/p>\n<p>\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5728\u5404\u4e2a\u53d1\u884c\u7248\u4e2d\uff0c\u90fd\u6709httpd\u670d\u52a1\u5668\u542f\u52a8\u811a\u672c\uff0c\u6bd4\u5982<br \/>\n# \/etc\/rc.d\/rc.httpd restart \u6ce8\uff1aSlackware Linux<\/p>\n<p># \/etc\/init.d\/apache2 restart \u6ce8\uff1aubuntu\u3001Debian \u7b49\uff1b<br \/>\n# \/etc\/init.d\/httpd start \u6ce8:Fedora \u3001Redhat\u3001CentOS<\/p>\n<p>\u8f6c\u81ea\uff1a<a href=\"http:\/\/blog.sina.com.cn\/s\/blog_70ac6bec01018mqa.html\">http:\/\/blog.sina.com.cn\/s\/blog_70ac6bec01018mqa.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache 2.x \u4e2dURL\u91cd\u5199\uff0c\u662f\u901a\u8fc7mod_rewrite.so \u6765\u5b9e\u73b0\u7684\uff0c\u6240\u4ee5\u60a8\u8981\u67e5\u770b\u60a8\u7684Apache &hellip; <a href=\"http:\/\/www.homconnect.cn\/?p=48\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clinux\u4e0b\u5f00\u542fapache\u7684url\u91cd\u5199\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,2],"tags":[28,29],"_links":{"self":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/48"}],"collection":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":1,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":49,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions\/49"}],"wp:attachment":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}