3

My htaccess file is giving my webpage a 500 error and I do not understand why ... this is the code:

 AddHandler application/x-httpd-php56 .php
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ /gallery-page.php?galerie=$1
  • If I take the .htaccess file away, then I get 404 errors on the pages I needed renaming.

  • If I have the .htaccess file with no code in it, I still get an error 500.

If somebody can help me understand, it would be great !

  • Often, RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d are not necessary. Try removing them and testing again. – closetnoc Apr 10 '16 at 16:36
  • There are plenty of similar results even from stackexchange if you query google the single lines and put it in quotes " for example "RewriteCond %{REQUEST_FILENAME} !-f" - dont have the opportunity to check in detail yet - may you find the solution , ill check back later. – user20874 Apr 10 '16 at 17:50
  • You'll need to check your error log - there you should find a more meaningful error. "If i have the .htaccess file with no code in it, I still get an error 500.", but without any .htaccess file it's OK (just a 404) - that doesn't make a whole lot of sense. It perhaps suggests there is "something else" going on? Why do you need the AddHandler line? There is nothing particularly wrong with the code you have posted. – MrWhite Apr 10 '16 at 18:00
  • @closetnoc Removing the %{REQUEST_FILENAME} !-f line would likely break the site (if this was working as intended)! That line is required to prevent static resources (CSS, JS, images, etc.) and any other static files from being rewritten. (Assuming static resources are being served from the same site.) – MrWhite Apr 10 '16 at 18:16
  • @w3dk I should just learn to leave these things to you!! You are the expert. I hardly deal with .htaccess much anymore. I may more in the future. Who knows?? Please do feel free to correct me when I am wrong or mistaken. I really do appreciate it!! I am jumping into different areas these days. I am working to junk my old sites and start over from scratch. However, I am so busy with life stuff lately, my attention is rather A.D.D. or stone slacker. Cheers!! – closetnoc Apr 10 '16 at 18:23
1

I haven't scoped for AddHandler application/x-httpd-php56 .php but I stake the following on all of my websites:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteBase /
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule>

Also, be sure to remove the HTTPS conditions if your site isn't SSL.

0

Your .htaccess syntax looks okay and running it through a validator confirms the syntax is fine. You can check your error log to see more information and see what is causing it but depending on your hosting environment (especially if it is a shared hosting server) you will probably find that the issue is the AddHandler application/x-httpd-php56 .php line. Many hosting providers prevent adding additional file handlers through .htaccess as it can cause security issues on the server. If your hosting provider does not already have PHP support on the server then simply adding that line to your .htaccess won't make it work and would produce a 500 error as there is no PHP installed on the server to process it, and if there is then the server will already be configured to handle PHP files and so there still would be no need to have that line added. Try removing that line and you should see it working.

  • Although the OP states, "If i have the .htaccess file with no code in it, I still get an error 500." – MrWhite Apr 11 '16 at 8:36
  • 1
    Sorry I did misread that, if that is the case then the hosting company has disabled .htaccess files in the vhost file and set AllowOverride None which in some configurations will just ignore the .htaccess file but in others will case a 500 error. Best bet in that case would be to chase the hosting provider and ask for .htaccess support or change hosts,but either way my answer still stands, there is no need on a shared host to add the AddHandler command in .htaccess. – Chris Rutherfurd Apr 11 '16 at 9:36
  • 1
    "AllowOverride None" - I had wondered this myself, but in my experience (and per the Apache docs - assuming 2.2) this always ignores the .htaccess file (which is supposed to be empty anyway). If this was to generate an error then the system must at least be checking for .htaccess files (doing more work), which AllowOverride None is supposed to avoid. My guess would be that the file contains invalid/invisible chars and is not truely empty. – MrWhite Apr 11 '16 at 11:22
  • 1
    "there is no need on a shared host to add the AddHandler command" - some (shared) hosts provide the ability to change PHP version with an AddHandler directive in .htaccess. (Which kind of looks like what is happening here... activating PHP 5.6 on a system that is perhaps 5.4 native.) Although, I agree, it does seem out of place. And certainly the first thing to remove when debugging. – MrWhite Apr 11 '16 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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