我想:
- 如果map文件中存在查询字符串值,则允许访问文件夹中的文件
- 如果查询字符串值为空或根本没有查询字符串,则禁用访问
使用以下命令,它可以工作,除了带有空格的文件:
/etc/httpd/额外的/httpd-ssl.conf
<VirtualHost *:443>
... truncated ssl certificate ...
RewriteEngine On
# Rewritemap:
RewriteMap filehash txt:file_hash.txt
# Query string equal to key=digits lookup in map
# redirect to /404 on fail else redirect to match in map
RewriteCond %{QUERY_STRING} ^(key=)([0-9]*)
RewriteRule ^/test/video/(.*)$ ${filehash:%2|/404}? [PT,NE,L]
# Query string empty: key=
RewriteCond %{QUERY_STRING} !^key=+$
RewriteRule ^/test/video/(.*)$ - [R=404,L]
# No query string
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/test/video/(.*)$ - [R=404,L]
</VirtualHost>
file_hash.txt
1001 /test/video/london_bridge_footage.mp4
1002 /test/video/london bridge footage.mp4
1003 /test/video/london%20bridge%20footage.mp4
1004 /test/video/london bridge footage.mp4
编辑:
添加了更多关于我的配置的信息,我有Codeigniter 4运行在up文件夹/test/谁使用重写规则
/etc/httpd/httpd . conf
<Directory "/var/www/test">
LogLevel alert rewrite:trace6
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
/var/www/测试/. htaccess
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /test
# Rewrite CSS / JS "theme.1603357209.css -> theme.css"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+).d+(.(?:js|css))$ $1$2
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([sS]*)$ index.php/$1 [L,NC,QSA]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
# Add cache control header one year for CSS and JS files
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
编辑2:
重写工作文件:
[Mon Jul 18 22:28:44.436405 2022] [core:notice] [pid 2002:tid 140071990364096] AH00094: Command line: '/usr/sbin/httpd'
[Mon Jul 18 22:28:49.518993 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london_bridge_footage.mp4 -> video/london_bridge_footage.mp4
[Mon Jul 18 22:28:49.519018 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] applying pattern '^(.+)\.\d+(\.(?:js|css))$' to uri 'video/london_bridge_footage.mp4'
[Mon Jul 18 22:28:49.519025 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london_bridge_footage.mp4 -> video/london_bridge_footage.mp4
[Mon Jul 18 22:28:49.519045 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] applying pattern '^' to uri 'video/london_bridge_footage.mp4'
[Mon Jul 18 22:28:49.519060 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london_bridge_footage.mp4 -> video/london_bridge_footage.mp4
[Mon Jul 18 22:28:49.520125 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] applying pattern '^' to uri 'video/london_bridge_footage.mp4'
[Mon Jul 18 22:28:49.520143 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london_bridge_footage.mp4 -> video/london_bridge_footage.mp4
[Mon Jul 18 22:28:49.520146 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] applying pattern '^([\s\S]*)$' to uri 'video/london_bridge_footage.mp4'
[Mon Jul 18 22:28:49.520161 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london_bridge_footage.mp4 -> video/london_bridge_footage.mp4
[Mon Jul 18 22:28:49.520165 2022] [rewrite:trace3] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] applying pattern '.*' to uri 'video/london_bridge_footage.mp4'
[Mon Jul 18 22:28:49.520170 2022] [rewrite:trace1] [pid 26321:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42860] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40139e0/initial] [perdir /var/www/test/] pass through /var/www/test/video/london_bridge_footage.mp4
失败的文件
[Mon Jul 18 22:32:19.837894 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london%20bridge%20footage.mp4 -> video/london%20bridge%20footage.mp4
[Mon Jul 18 22:32:19.837918 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] applying pattern '^(.+)\.\d+(\.(?:js|css))$' to uri 'video/london%20bridge%20footage.mp4'
[Mon Jul 18 22:32:19.837924 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london%20bridge%20footage.mp4 -> video/london%20bridge%20footage.mp4
[Mon Jul 18 22:32:19.837927 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] applying pattern '^' to uri 'video/london%20bridge%20footage.mp4'
[Mon Jul 18 22:32:19.837942 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london%20bridge%20footage.mp4 -> video/london%20bridge%20footage.mp4
[Mon Jul 18 22:32:19.837945 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] applying pattern '^' to uri 'video/london%20bridge%20footage.mp4'
[Mon Jul 18 22:32:19.837948 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/video/london%20bridge%20footage.mp4 -> video/london%20bridge%20footage.mp4
[Mon Jul 18 22:32:19.837951 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] applying pattern '^([\s\S]*)$' to uri 'video/london%20bridge%20footage.mp4'
[Mon Jul 18 22:32:19.837956 2022] [rewrite:trace2] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] rewrite 'video/london%20bridge%20footage.mp4' -> 'index.php/video/london%20bridge%20footage.mp4'
[Mon Jul 18 22:32:19.837966 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] add per-dir prefix: index.php/video/london%20bridge%20footage.mp4 -> /var/www/test/index.php/video/london%20bridge%20footage.mp4
[Mon Jul 18 22:32:19.837970 2022] [rewrite:trace2] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] trying to replace prefix /var/www/test/ with /test
[Mon Jul 18 22:32:19.837973 2022] [rewrite:trace1] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f40128a0/initial] [perdir /var/www/test/] internal redirect with /test/index.php/video/london%20bridge%20footage.mp4 [INTERNAL REDIRECT]
[Mon Jul 18 22:32:19.838010 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] add path info postfix: /var/www/test/index.php -> /var/www/test/index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838015 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/index.php/video/london bridge footage.mp4 -> index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838018 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] applying pattern '^(.+)\.\d+(\.(?:js|css))$' to uri 'index.php/video/london bridge footage.mp4'
[Mon Jul 18 22:32:19.838022 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] add path info postfix: /var/www/test/index.php -> /var/www/test/index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838025 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/index.php/video/london bridge footage.mp4 -> index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838027 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] applying pattern '^' to uri 'index.php/video/london bridge footage.mp4'
[Mon Jul 18 22:32:19.838046 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] add path info postfix: /var/www/test/index.php -> /var/www/test/index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838049 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/index.php/video/london bridge footage.mp4 -> index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838054 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] applying pattern '^' to uri 'index.php/video/london bridge footage.mp4'
[Mon Jul 18 22:32:19.838057 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] add path info postfix: /var/www/test/index.php -> /var/www/test/index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838062 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/index.php/video/london bridge footage.mp4 -> index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838065 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] applying pattern '^([\s\S]*)$' to uri 'index.php/video/london bridge footage.mp4'
[Mon Jul 18 22:32:19.838070 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] add path info postfix: /var/www/test/index.php -> /var/www/test/index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838074 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/index.php/video/london bridge footage.mp4 -> index.php/video/london bridge footage.mp4
[Mon Jul 18 22:32:19.838076 2022] [rewrite:trace3] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] applying pattern '.*' to uri 'index.php/video/london bridge footage.mp4'
[Mon Jul 18 22:32:19.838081 2022] [rewrite:trace1] [pid 26391:tid 140071799514688] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400cc00/initial/redir#1] [perdir /var/www/test/] pass through /var/www/test/index.php
[Mon Jul 18 22:32:20.061135 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.1658174761.js -> assets/dist/js/theme.1658174761.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061153 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] applying pattern '^(.+)\.\d+(\.(?:js|css))$' to uri 'assets/dist/js/theme.1658174761.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061170 2022] [rewrite:trace2] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] rewrite 'assets/dist/js/theme.1658174761.js' -> 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061174 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] add per-dir prefix: assets/dist/js/theme.js -> /var/www/test/assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061177 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061180 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] applying pattern '^' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061197 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061201 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] applying pattern '^' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061205 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061208 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] applying pattern '^([\s\S]*)$' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061213 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061217 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] applying pattern '.*' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061225 2022] [rewrite:trace2] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] trying to replace prefix /var/www/test/ with /test, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061228 2022] [rewrite:trace1] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f4017a10/initial] [perdir /var/www/test/] internal redirect with /test/assets/dist/js/theme.js [INTERNAL REDIRECT], referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061246 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061251 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] applying pattern '^(.+)\.\d+(\.(?:js|css))$' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061255 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061258 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] applying pattern '^' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061271 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061275 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] applying pattern '^' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061278 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061281 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] applying pattern '^([\s\S]*)$' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061289 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] strip per-dir prefix: /var/www/test/assets/dist/js/theme.js -> assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061293 2022] [rewrite:trace3] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] applying pattern '.*' to uri 'assets/dist/js/theme.js', referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
[Mon Jul 18 22:32:20.061299 2022] [rewrite:trace1] [pid 26391:tid 140071791121984] mod_rewrite.c(486): [client 192.168.1.254:42862] 192.168.1.254 - - [my-domain.org/sid#5561d7dc23b8][rid#7f64f400b7d0/initial/redir#1] [perdir /var/www/test/] pass through /var/www/test/assets/dist/js/theme.js, referer: https://my-domain.org/test/video/london%20bridge%20footage.mp4?key=1003
可能和这个有关?
3编辑
根据Anubhava的建议,我复制了他的。htaccess,但它没有工作,文件是可访问的或没有查询字符串,我已经编辑如下这两行:
# with + instead of * ?key= return the file
RewriteCond %{QUERY_STRING} ^key=(d*) [NC]
# Without ? internal server error
RewriteRule ^video/ ${filehash:%1}? [L,NC]
正在工作:
- map适用于所有类型的文件,带或不带空格如果提供了查询字符串?key=digits
- 如果查询字符串为?key=或?key=0000,则不返回文件
- 如果不匹配映射,前端控制器返回404
什么不工作:
- 文件是可下载的,如果我使用任何uri之间的文件扩展名和查询字符串等号:
https://my-site.org/test/video/london%20bridge%20footage.mp4?key
在过去的几个小时里,我测试了很多不同的版本,但都没有成功。
Httpd is 2.4.54
帮助欣赏
编辑4:
它现在正在工作,非常感谢Anubhava的帮助,解决方案是在另一个由Anubhava解决的帖子中
# Query string equal to key=digits lookup in map
RewriteCond %{QUERY_STRING} ^key=(d*) [NC]
RewriteRule ^video/ ${filehash:%1}? [L,NC,NE]
# for video URL if key=<digits> is not present then 404
RewriteCond %{QUERY_STRING} !(^|&)key=(d+) [NC]
# prevent looping from internal redirects
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^video/ /404/ [L,NC]
5编辑
与此同时,Anubhava提供了另一个可行的解决方案。
我建议您从vhost中删除除RewriteMap
以外的所有规则,并将所有规则保留在一个地方,即test/.htaccess
,因为它已经存在于您的文件系统中。
/etc/httpd/额外的/httpd-ssl.conf:
<VirtualHost *:443>
... truncated ssl certificate ...
RewriteEngine On
# Rewritemap:
RewriteMap filehash txt:file_hash.txt
</VirtualHost>
/测试/. htaccess:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /test/
# Rewrite CSS / JS "theme.1603357209.css -> theme.css"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+).d+(.(?:js|css))$ $1$2 [L,NC]
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301,NE]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
# for video URL if key=<digits> is not present then 404
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} !(^|&)key=(d+) [NC]
RewriteRule ^video/ /404/ [L,NC]
# Query string equal to key=digits lookup in map
# redirect to /404 on fail else redirect to match in map
RewriteCond %{QUERY_STRING} ^key=(d+) [NC]
RewriteRule ^video/ ${filehash:%1|/404/}? [L,NC]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php%{REQUEST_URI} [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Add cache control header one year for CSS and JS files
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
也不应该使用R=404
规则,因为index.php
作为前端控制器处理所有非文件,非目录请求。