Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to avoid .htaccess completely, and put your rewrite rules for Craft CMS in an Apache .conf file
# Using .htaccess is something you should avoid if at all possible, due to performance concerns:
# https://httpd.apache.org/docs/current/howto/htaccess.html
# Here's how to implement the rewrite rules for CraftCMS in an Apache .conf file; the key
# part is the "## Removes index.php from Craft URLs ##" section; the rest is provided
# just for context. Enjoy - andrew@nystudio107.com
<VirtualHost *:80>
ServerName BradsForMen.com
ServerAlias *.BradsForMen.com
DocumentRoot /var/www/BradsForMen/public
CustomLog /var/log/httpd/BradsForMen.com-access.log combined
ErrorLog /var/log/httpd/BradsForMen.com-error.log
## Canonical domain rewrite ##
<If "%{HTTP_HOST} != 'BradsForMen.com'">
Redirect "/" "http://BradsForMen.com/"
</If>
<Directory /var/www/BradsForMen>
Options FollowSymLinks
AllowOverride None
## Removes index.php from Craft URLs ##
<IfModule mod_rewrite.c>
RewriteEngine On
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule ^(.+) /index.php?p=$1 [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment