Rewrites and derps

So I’ve got a customer who came to me for help with his .htaccess.

He’s got a site with a subfolder that has a .htaccess with custom 404s. All good, right? Right. So, what’s the problem, then? The problem is that his main site also has .htaccess. The two seem to be interfering with each other and generating an infinite loop.

Main site .htaccess:


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /view.php?id=$1 [L,QSA]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# END SSL config

Subfolder .htaccess:


ErrorDocument 404 https://mypastebin.com/vice/404.php

I also tried with some variations of /404.php, /vice/404.php and full URLs, etc. None of it is working.

I tried with this:


ErrorDocument 404 https://mypastebin.com/vice/404.php
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Obviously, this doesn’t quite work and usually results in:


[Tue Oct 18 07:19:32.109454 2016] [core:error] [pid 18255] [client xxx.xxx.xxx.xx:11271] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Any idears, folks?

[QUOTE=Keiro;29148]
[…]
Any idears, folks?[/QUOTE]

Turns out I finally hit on a combination that worked.


ErrorDocument 404 https://mypastebin.com/vice/404.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Hi Kerio
I set error pages directly in httpd.conf, which seems to work lovely without any redirects, and I have had not received any reports from clients that error pages not working as expected.
I hope that helps
Many thanks
John
Just add at the bottom of httpd.conf, save and restart apache
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html