Skip to content

Instantly share code, notes, and snippets.

@hujuice
Last active June 23, 2021 05:23
Show Gist options
  • Save hujuice/4c8a5ab4ff41b37e9cbce172930af71a to your computer and use it in GitHub Desktop.
Save hujuice/4c8a5ab4ff41b37e9cbce172930af71a to your computer and use it in GitHub Desktop.
Apache VirtualHost configuration for yii2-app-advanced, one domain
# /path/to/application/apache.conf
# UTF-8 forever!
# ==============================
AddDefaultCharset utf-8
# Main URL rewriting rules
# ==============================
RewriteEngine On
# If $showScriptName is false in UrlManager, do not allow accessing URLs with script name
RewriteRule ^(/backend)?/index.php/ - [L,R=404]
# Protect against access to special files
RewriteRule \.(htaccess|htpasswd|svn|git) - [L,R=404]
# Frontend
# ==============================
DocumentRoot /path/to/application/frontend/web
<Directory /path/to/application/frontend/web>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
# Use mod_rewrite for pretty URL support
RewriteEngine On
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
</Directory>
# Backend
# ==============================
Alias /backend /path/to/application/backend/web
<Directory /path/to/application/backend/web>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
# Use mod_rewrite for pretty URL support
RewriteEngine On
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
</Directory>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment