Skip to content

Instantly share code, notes, and snippets.

@johnwbaxter
Forked from khalwat/BradsForMen.conf
Created July 13, 2016 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnwbaxter/f3279b2b5997f07168d1241d8ef45e32 to your computer and use it in GitHub Desktop.
Save johnwbaxter/f3279b2b5997f07168d1241d8ef45e32 to your computer and use it in GitHub Desktop.
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