{"id":5634,"date":"2019-04-19T10:59:06","date_gmt":"2019-04-19T02:59:06","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=5634"},"modified":"2021-03-30T15:34:18","modified_gmt":"2021-03-30T07:34:18","slug":"htaccess-%e8%bd%89%e5%9d%80","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=5634","title":{"rendered":".htaccess \u8f49\u5740"},"content":{"rendered":"<p>--<\/p>\n<h2>\u7dda\u4e0a\u6e2c\u8a66 .htaccess \u683c\u5f0f\u8a9e\u6cd5<\/h2>\n<ul>\n<li><a href=\"https:\/\/htaccess.madewithlove.be\/\" target=\"_blank\" rel=\"noopener\">Test your htaccess rewrite rules<\/a><\/li>\n<\/ul>\n<p>\u50c5\u4f9b\u53c3\u8003\uff0c\u652f\u63f4\u662f\u5426\u4e0d\u8db3\uff0c\u90e8\u4efd\u8a9e\u6cd5\u7121\u6cd5\u8fa8\u8b58<\/p>\n<p>--<\/p>\n<ul>\n<li><a title=\".htaccess\u6280\u5de7: URL\u91cd\u5199(Rewrite)\u4e0e\u91cd\u5b9a\u5411(Redirect)\" href=\"https:\/\/lesca.me\/archives\/htaccess-rewrite.html\" target=\"_blank\" rel=\"noopener\">.htaccess\u6280\u5de7: URL\u91cd\u5199(Rewrite)\u4e0e\u91cd\u5b9a\u5411(Redirect)<\/a><\/li>\n<li><a href=\"https:\/\/blog.hinablue.me\/apache-note-about-some-rewrite-note-2011-05\/\" target=\"_blank\" rel=\"noopener\">[Rewrite note.] \u91cd\u5beb\u898f\u5247\u7b46\u8a18<\/a><\/li>\n<\/ul>\n<p>--<\/p>\n<h2>404 \u8f49\u5230\u67d0\u4e00\u9801<\/h2>\n<pre class=\"lang:default decode:true\">RewriteEngine on\r\nErrorDocument 404 https:\/\/www.oikid.com<\/pre>\n<p>--<\/p>\n<h2>\u8f49\u5230 HTTPS:\/\/<\/h2>\n<pre class=\"lang:default decode:true \">RewriteEngine on\r\nRewriteCond %{SERVER_PORT} !^443$\r\nRewriteRule ^(.*)?$ https:\/\/%{SERVER_NAME}\/$1 [L,R]<\/pre>\n<p>--<\/p>\n<h2>\u5c07 A \u7db2\u7ad9\u7684\u7db2\u9801\u5c0d\u61c9\u5230 B \u7db2\u7ad9\u7684\u540c\u4e00\u7db2\u9801<\/h2>\n<pre class=\"lang:default decode:true\">RewriteEngine on\r\nRewriteRule ^.*$ https:\/\/www.b.com%{REQUEST_URI} [L,R]<\/pre>\n<p>--<\/p>\n<h2>RewriteCond \u5efa\u7acb\u689d\u4ef6<\/h2>\n<p>RewriteCond \u53ef\u4ee5\u5148\u5c0d\u7db2\u5740\u5206\u6790\uff0c\u7b26\u5408\u689d\u4ef6\u624d\u9032\u884c\u8655\u7406<\/p>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/12050590\/redirect-non-www-to-www-in-htaccess\" target=\"_blank\" rel=\"noopener\">Redirect non-www to www in .htaccess<\/a><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">RewriteCond %{HTTP_HOST} ^hoyo.idv.tw$ [NC]\r\nRewriteRule (.*) https:\/\/www.hoyo.idv.tw\/$1 [R=301,L]<\/pre>\n<p>--<\/p>\n<h2>Log<\/h2>\n<p>\u7d00\u9304 Log \u8a2d\u5b9a\u53ea\u80fd\u5beb\u5728 httpd.conf \u5167\uff0c\u4e0d\u662f\u5beb\u5728 .htaccess<\/p>\n<p>Log \u53ea\u5728\u4f5c\u7528\u6642\u7d00\u9304\uff0c500 \u932f\u8aa4\u7684\u8a2d\u5b9a\u662f\u6c92\u6709\u7d00\u9304\u7684\uff0c\u610f\u601d\u5c31\u662f\u9084\u662f\u8981\u9760\u81ea\u5df1\u7528\u731c\u7684\u9664\u932f<\/p>\n<pre class=\"lang:default decode:true\">&lt;VirtualHost *:80&gt;\r\n    ServerName hoyo.idv.tw\r\n    DocumentRoot \/WEBSite\/www\/WWW\r\n\r\n    RewriteLogLevel 3\r\n    RewriteLog \"\/var\/log\/httpd\/htaccess.log\"\r\n\r\n    &lt;Directory \"\/WEBSite\/www\/WWW\"&gt;\r\n       AllowOverride All\r\n    &lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5634\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;6,902&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- \u7dda\u4e0a\u6e2c\u8a66 .htacce...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"5634\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;6,902&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5634"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5634"}],"version-history":[{"count":9,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5634\/revisions"}],"predecessor-version":[{"id":8053,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/5634\/revisions\/8053"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}