Apache-Httpd
即使文件存在,Apache RewriteCond 在“REQUEST_FILENAME”上也不匹配?
跟踪日誌:
apache_1 | [Wed Nov 20 17:14:43.950796 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] init rewrite engine with requested uri /css/main.css apache_1 | [Wed Nov 20 17:14:43.950822 2019] [rewrite:trace3] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] applying pattern '^' to uri '/css/main.css' apache_1 | [Wed Nov 20 17:14:43.950836 2019] [rewrite:trace4] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] RewriteCond: input='/css/main.css' pattern='-f' => not-matched apache_1 | [Wed Nov 20 17:14:43.950839 2019] [rewrite:trace3] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] applying pattern '^' to uri '/css/main.css' apache_1 | [Wed Nov 20 17:14:43.950842 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] rewrite '/css/main.css' -> '/index.php' apache_1 | [Wed Nov 20 17:14:43.950845 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] local path result: /index.php apache_1 | [Wed Nov 20 17:14:43.950850 2019] [rewrite:trace2] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] prefixed with document_root to /var/www/html/public/index.php apache_1 | [Wed Nov 20 17:14:43.950852 2019] [rewrite:trace1] [pid 9:tid 140252198749952] mod_rewrite.c(483): [client 172.18.0.1:54078] 172.18.0.1 - - [localhost/sid#7f8f031725e8][rid#7f8f0078a0a0/initial] go-ahead with /var/www/html/public/index.php [OK]
重要的一點是:
RewriteCond: input='/css/main.css' pattern='-f' => not-matched
為什麼找不到文件?它肯定在那裡。
配置有:
DocumentRoot /var/www/html/public/
該文件位於:
/var/www/html/public/css/main.css
.在apache上執行
strace
我看到以下內容:apache_1 | [pid 11] poll([{fd=9, events=POLLIN}], 1, 3000 <unfinished ...> apache_1 | [pid 10] <... select resumed> ) = 0 (Timeout) apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0 apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112492 apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout) apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0 apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112592 apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0}) = 0 (Timeout) apache_1 | [pid 10] wait4(-1, 0x7ffd156f4e0c, WNOHANG|WSTOPPED, NULL) = 0 apache_1 | [pid 10] times({tms_utime=2, tms_stime=13, tms_cutime=0, tms_cstime=0}) = 478112692 apache_1 | [pid 10] select(0, NULL, NULL, NULL, {tv_sec=1, tv_usec=0} <unfinished ...> apache_1 | [pid 67] <... epoll_wait resumed> [{EPOLLIN, {u32=3893182512, u64=140578172780592}}], 52, -1) = 1 apache_1 | [pid 59] <... epoll_wait resumed> [{EPOLLIN, {u32=3893182512, u64=140578172780592}}], 52, -1) = 1 apache_1 | [pid 67] accept4(3, <unfinished ...> apache_1 | [pid 59] accept4(3, <unfinished ...> apache_1 | [pid 67] <... accept4 resumed> {sa_family=AF_INET, sin_port=htons(42176), sin_addr=inet_addr("172.18.0.1")}, [128->16], SOCK_CLOEXEC) = 16 apache_1 | [pid 59] <... accept4 resumed> 0x7fda85ffad30, [128], SOCK_CLOEXEC) = -1 EAGAIN (Resource temporarily unavailable) apache_1 | [pid 67] futex(0x7fdae80d3160, FUTEX_WAKE_PRIVATE, 1) = 1 apache_1 | [pid 59] epoll_wait(13, <unfinished ...> apache_1 | [pid 67] epoll_wait(13, <unfinished ...> apache_1 | [pid 22] <... futex resumed> ) = 0 apache_1 | [pid 22] futex(0x7fdae80d30e8, FUTEX_WAKE_PRIVATE, 1) = 0 apache_1 | [pid 22] getsockname(16, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("172.18.0.3")}, [128->16]) = 0 apache_1 | [pid 22] fcntl(16, F_GETFL) = 0x2 (flags O_RDWR) php-main_1 | - - 20/Nov/2019:17:40:08 +0000 "GET /css/main.css" 200 apache_1 | [pid 22] fcntl(16, F_SETFL, O_RDWR|O_NONBLOCK) = 0 apache_1 | [pid 22] read(16, "GET /css/main.css HTTP/1.1\r\nHost"..., 8000) = 90 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966703 2019"..., 249[Wed Nov 20 17:40:08.966703 2019] [rewrite:trace2] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] init rewrite engine with requested uri /css/main.css apache_1 | ) = 249 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966779 2019"..., 240[Wed Nov 20 17:40:08.966779 2019] [rewrite:trace3] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] applying pattern '^' to uri '/css/main.css' apache_1 | ) = 240 apache_1 | [pid 22] stat("/css/main.css", 0x7fdae534f8d0) = -1 ENOENT (No such file or directory) apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966875 2019"..., 259[Wed Nov 20 17:40:08.966875 2019] [rewrite:trace4] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] RewriteCond: input='/css/main.css' pattern='-f' => not-matched apache_1 | ) = 259 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966925 2019"..., 240[Wed Nov 20 17:40:08.966925 2019] [rewrite:trace3] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] applying pattern '^' to uri '/css/main.css' apache_1 | ) = 240 apache_1 | [pid 22] getpid() = 13 apache_1 | [pid 22] write(6, "[Wed Nov 20 17:40:08.966980 2019"..., 236[Wed Nov 20 17:40:08.966980 2019] [rewrite:trace2] [pid 13:tid 140578125055744] mod_rewrite.c(483): [client 172.18.0.1:42176] 172.18.0.1 - - [localhost/sid#7fdae7cfe5e8][rid#7fdae43100a0/initial] rewrite '/css/main.css' -> '/index.php'
編輯
為什麼 Apache 試圖閱讀
/css/main.css
?為什麼它不在那裡使用文件根目錄
https://serverfault.com/questions/78125/mod-rewrite-request-filename-doesnt-contain-absolute-path
REQUEST_FILENAME
似乎返回一個不同的值取決於它是否在 ApaChe 配置 ORRRR 中.htaccess
…