2

My .htaccess is displayed below.

It catches example.com/abcnonsense and sends it to my error page - 404error.htm.

But fails to catch example.com/abcnonsense.htm or example.com/abcnonsense.html.

In these cases it redirects to my home page.

Can anyone see where I am going wrong?

ErrorDocument 404 /404error.htm

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^myexample\.com
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://www.myexample.com/$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{DOCUMENT_ROOT}/index.html -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^$ /index.html [NC,L]

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.html$ / [NC,R,L]

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.htm$ / [NC,R,L]

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^$ /index.htm

RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*\.x?h?t?ml?)$ /cgi-bin/cms.cgi?a=pg&p=%{REQUEST_URI}&%{QUERY_STRING} [NC,L]
1
RewriteRule ^(.*\.x?h?t?ml?)$ /cgi-bin/cms.cgi?a=pg&p=%{REQUEST_URI}&%{QUERY_STRING} [NC,L]

Because the very last line rewrites all .htm and .html requests to your /cgi-bin/cms.cgi script. Any 404's that result from .htm or .html requests would therefore need to be managed by this script. In other words, your CMS needs to manage the 404, not Apache.

EDIT: Unless... your CMS only works on .htm or .html files that physically exist on the filesystem? (Although I doubt this.)

7
  • What happens if I remove the last line? Would that solve it? – Mike Apr 21 '17 at 16:50
  • Ok i tried that and the whole site went down. – Mike Apr 21 '17 at 17:07
  • What do i need to put in the cms.cgi to catch the 404 and send it to my error page - 404error.htm ? – Mike Apr 21 '17 at 17:45
  • Yes, if you remove that line then it will resolve your immediate problem of triggering your 404 ErrorDocument, but none of your URLs will be routed through your CMS script, so the "site will go down". Unfortunately, exactly how you would need to edit your cms.cgi script to handle such errors is out of scope for this site - we would need to see your entire script. We don't even know what language it is written in? Does it connect to a database? etc. etc. – MrWhite Apr 21 '17 at 17:50
  • looks like it is written in Perl – Mike Apr 21 '17 at 17:53

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.