1

I was getting an 'unknown error' when trying to access the admin. I couldn't see anything in the Craft logs apart from 404 related errors. I replaced the app folder but still no luck, eventually I discovered it was a rewrite rule in my .htaccess causing the problem.

# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.(php|htm?)
RewriteRule ^ /%1 [L,R=301]

I'd love to understand why, and how I can get around this in the future?

3
  • 1
    Out of interest - why are needing to do this? Craft can handle this for you. Aug 19, 2016 at 14:00
  • I didn't know it could! Can you point me to where to look?
    – sarah3585
    Aug 19, 2016 at 14:05
  • It won't handle it per say but the convention when building a Craft site is to generally not use php files (craftcms.stackexchange.com/questions/722/…). For htm you can just rename these to html and the extension will be removed automatically if placed in the template directory. Aug 19, 2016 at 14:13

1 Answer 1

2

It might be down to the order you have the code in your htaccess file? Did you try putting your code above the Craft rewrite code?

# redirect PHP or HTM to no extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.(php|htm?)
RewriteRule ^ /%1 [L,R=301]

# 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]

Also I tend to exclude certain directories when I don't want rewrites to apply. One way to do this would be;

# ------------------------------------------------------------------------------
# | Exclude directories from the rewrite rules                                 |
# ------------------------------------------------------------------------------
RewriteRule ^craft - [L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.