1+ # Global configuration for the public directory
12<Directory /app/public>
23 Options FollowSymLinks
34 AllowOverride All
45 Require all granted
6+
7+ # Ensure Apache serves static files directly
8+ <FilesMatch "\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$">
9+ Header unset ETag
10+ FileETag None
11+
12+ # Completely disable PHP processing for these files
13+ RemoveHandler .php
14+ SetHandler default-handler
15+ </FilesMatch>
516</Directory>
617
18+ # HTTP Virtual Host - Redirect to HTTPS
719<VirtualHost *:80>
8- # The ServerName directive sets the request scheme, hostname and port that
9- # the server uses to identify itself. This is used when creating
10- # redirection URLs. In the context of virtual hosts, the ServerName
11- # specifies what hostname must appear in the request's Host: header to
12- # match this virtual host. For the default virtual host (this file) this
13- # value is not decisive as it is used as a last resort host regardless.
14- # However, you must set it for any further virtual host explicitly.
15- #ServerName example.com
16- #ServerAlias www.example.com
17-
1820 ServerAdmin webmaster@localhost
1921 DocumentRoot /app/public
2022
21- # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
22- # error, crit, alert, emerg.
23- # It is also possible to configure the loglevel for particular
24- # modules, e.g.
25- #LogLevel info ssl:warn
23+ # Redirect all HTTP to HTTPS
24+ RewriteEngine On
25+ RewriteCond %{HTTPS} off
26+ RewriteRule ^(.*)$ https://localhost:8443%{REQUEST_URI} [R=301,L]
2627
28+ # Logging configuration
2729 ErrorLog ${APACHE_LOG_DIR}/error.log
2830 CustomLog ${APACHE_LOG_DIR}/access.log combined
31+ </VirtualHost>
32+
33+ # HTTPS Virtual Host
34+ <VirtualHost *:443>
35+ # ServerName directive, which sets the request scheme, hostname and port that
36+ ServerName localhost
37+ ServerAdmin webmaster@localhost
38+ DocumentRoot /app/public
39+
40+ # SSL Configuration
41+ SSLEngine on
42+ SSLCertificateFile /app/docker/ssl/localhost.pem
43+ SSLCertificateKeyFile /app/docker/ssl/localhost-key.pem
44+
45+ # Enable rewrite logging for debugging (remove in production)
46+ LogLevel warn rewrite:trace6
47+
48+ # Yii2 URL Rewriting Configuration
49+ RewriteEngine On
50+
51+ # Step 1: Exclude static files by extension completely
52+ RewriteRule \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|map)$ - [L,QSA]
53+
54+ # Step 2: Exclude specific asset directories by path
55+ RewriteRule ^(assets|image|images|css|js|fonts|media)/ - [L,QSA]
56+
57+ # Step 3: If it's an existing file, serve it directly
58+ RewriteCond %{REQUEST_FILENAME} -f
59+ RewriteRule ^ - [L]
60+
61+ # Step 4: If it's an existing directory, serve it directly
62+ RewriteCond %{REQUEST_FILENAME} -d
63+ RewriteRule ^ - [L]
64+
65+ # Step 5: Only if none of the above apply, send to index.php
66+ RewriteRule ^(.*)$ index.php [L,QSA]
2967
30- # For most configuration files from conf-available/, which are
31- # enabled or disabled at a global level, it is possible to
32- # include a line for only one particular virtual host. For example the
33- # following line enables the CGI configuration for this host only
34- # after it has been globally disabled with "a2disconf".
35- #Include conf-available/serve-cgi-bin.conf
36- </VirtualHost>
68+ # Logging configuration for SSL
69+ ErrorLog ${APACHE_LOG_DIR}/ssl_error.log
70+ CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
71+ </VirtualHost>
0 commit comments