Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save terryupton/e98e6f37182c9abe3e526e5a90ebf2bd to your computer and use it in GitHub Desktop.
Save terryupton/e98e6f37182c9abe3e526e5a90ebf2bd to your computer and use it in GitHub Desktop.
I have the following in my .htaccess file
```
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# ------------------------------------------------------------------------------
# | Redirect to top level /index.php to the root (www) |
# ------------------------------------------------------------------------------
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
# ------------------------------------------------------------------------------
# | Add trailing slash to urls |
# ------------------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# ------------------------------------------------------------------------------
# | Remove .php-extension from urls |
# ------------------------------------------------------------------------------
#This removes php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)/$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
</IfModule>
# ------------------------------------------------------------------------------
# | Filename-based cache busting |
# ------------------------------------------------------------------------------
# If you're not using a build process to manage your filename version revving,
# you might want to consider enabling the following directives to route all
# requests such as `/css/style.12345.css` to `/css/style.css`.
# To understand why this is important and a better idea than `*.css?v231`, read:
# http://stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
</IfModule>
```
@j-greig
Copy link

j-greig commented May 31, 2019

Add a trailing slash:
rewrite ^/(.*)/$ /$1 permanent;

Cache-busting:
Check out https://github.com/nystudio107/nginx-craft/blob/master/nginx-partials/cache-busting.conf

And might be more clues for you at https://github.com/nystudio107/nginx-craft :)

@terryupton
Copy link
Author

terryupton commented May 31, 2019

Thanks @j-greig.
Where as a .htaccess would sit in the root - where does this stuff live in terms of the project directory and naming etc?
I’m Using valet locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment