Apache 重写文件映射规则

来自姬鸿昌的知识库
跳到导航 跳到搜索
[root@iZ8vbcjkeqbrdmmbt23vboZ ~]# docker exec -it aade5ae73079 bash
root@aade5ae73079:/var/www/html# vim /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
        AllowEncodedSlashes NoDecode

        RewriteEngine on
        RewriteCond %{SERVER_PORT} !^443$
        RewriteRule ^videos/([^/\.]+)\.mp4$ /var/www/videos/$1.mp4 [L]
        RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]
</VirtualHost>

在Apache的RewriteRule规则中,[L]标志表示“最后一个”或“最后的”标志(Last Flag)。

它指示Apache在应用规则后停止处理其他规则。

如果[L]标志未设置,则Apache将继续处理其余的规则。

root@aade5ae73079:/var/www/html# service apache2 restart
Restarting Apache httpd web server: apache2Terminated
root@aade5ae73079:/var/www/html# [root@iZ8vbcjkeqbrdmmbt23vboZ ~]# 
[root@iZ8vbcjkeqbrdmmbt23vboZ ~]# docker start aade5ae73079
aade5ae73079