LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   CentOS (https://www.linuxquestions.org/questions/centos-111/)
-   -   CGI execution error whenever I use htaccess file (https://www.linuxquestions.org/questions/centos-111/cgi-execution-error-whenever-i-use-htaccess-file-4175626485/)

Mario Lima 03-27-2018 08:51 PM

CGI execution error whenever I use htaccess file
 
Hello,

I have a Linux Server, running Centos 6.9, Apache 2.2.15, Postfix 2.6.6 and all those known common stuff.

In order to set Error pages, Cache time for some types of files, as well as to adapt to Google requirements about having Domains with and without "www", I have at each Domain's root directory, an .htaccess file like this one you can see at the bottom.

The problem: if under any Domain I have a Site which uses .cgi files, they all stop working and I receive messages like Page Not Found for any of them.

In order to avoid this error I have to comment out all the Redirect lines, as you can see in the .htaccess below.

So, please, I need help, because I need such an .htaccess file, but my CGI's have to keep working.

Thanks a lot in advance.

Mario Lima./
_______________________________________________________________
Code:

.htaccess file

<IfModule mod_expires.c>
ExpiresActive On
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg
ExpiresByType application/vnd.ms-fontobject "access 1 year"
ExpiresByType application/x-font-ttf "access 1 year"
ExpiresByType application/x-font-opentype "access 1 year"
ExpiresByType application/x-font-woff "access 1 year"
ExpiresByType image/svg+xml "access 1 year"
ExpiresByType text/html "access 1 hour"
ExpiresByType text/css "access 14 days"
ExpiresByType text/x-javascript "access 3 weeks"
ExpiresByType application/javascript "access 1 month" 
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType image/gif "access 2 months"
ExpiresByType image/png "access 2 months"
ExpiresByType image/jpg "access 2 months"
ExpiresByType image/jpeg "access 2 months"
ExpiresByType image/gif "access 2 months"
ExpiresByType application/pdf "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>

<IfModule mod_rewrite.c>
#aRewriteCond %{HTTP_HOST} ^66\.226\.75\.86
#RewriteRule (.*) http://www.corretoresdeseguros.com.br/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
#RewriteRule (.*) http://corretoresdeseguros.com.br/$1 [R=301,L]
#RewriteEngine on
#rewritecond %{http_host} ^corretoresdeseguros.com.br [nc]
#rewriterule ^(.*)$ http://www.corretoresdeseguros.com.br/$1 [r=301,nc]
Options +FollowSymlinks
</IfModule>

ErrorDocument 400 /pagina-erro-400.html
ErrorDocument 401 /pagina-erro-401.html
ErrorDocument 403 /pagina-erro-403.html
ErrorDocument 404 /pagina-erro-404.html
ErrorDocument 500 /pagina-erro-500.html


bathory 03-28-2018 07:27 AM

Quote:

The problem: if under any Domain I have a Site which uses .cgi files, they all stop working and I receive messages like Page Not Found for any of them.
Could you please post the exact error from the apache error_log?


Quote:

In order to avoid this error I have to comment out all the Redirect lines, as you can see in the .htaccess below.
You can ditch mod_rewrite and use a virtual host like this:
Code:

<VirtualHost *:80>
ServerName www.corretoresdeseguros.com.br
ServerAlias corretoresdeseguros.com.br
<- The rest of vhost stuff ->
</VirtualHost>

Regards

Mario Lima 03-28-2018 08:01 AM

Hi, bathory,

Thanks for your help. As a matter of fact, all of our Domains have <virtualhost> blocks with ServerName and ServerAlias, like this you mentioned.

When I activate the .htaccess file, the error which occurs to any CGI we try to use is:

PAGE NOT FOUND

Regards.

Mário./

bathory 03-28-2018 08:47 AM

Quote:

Thanks for your help. As a matter of fact, all of our Domains have <virtualhost> blocks with ServerName and ServerAlias, like this you mentioned.

When I activate the .htaccess file, the error which occurs to any CGI we try to use is:

PAGE NOT FOUND
So since you have both names, there is no need of the rewrite rules. Apache can serve stuff like pages, cgi scripts etc, using both names.
Unless you want to do something else, i.e. use mandatory www prefix.

And please post the error from the apache logfile (in Centos is in /var/log/httpd/error_log), so we could see why you get the "PAGE NOT FOUND" error in the browser.

Mario Lima 03-28-2018 09:30 AM

Hi, bathory,

1) We use these lines with redirect because Google requires to do this way, so that Google does not consider with "www" and without "www" as being two different sites.

2) The error log messages are like this one:

[Wed Mar 28 11:20:03 2018] [error] [client 201.6.232.101] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/html/multisites/www/cgi-multisites/ezformmx.cgi

bathory 03-28-2018 11:59 AM

Quote:

1) We use these lines with redirect because Google requires to do this way, so that Google does not consider with "www" and without "www" as being two different sites.
That's what I' telling you.
If you have both names (with and without the www prefix) in the apache ServerName/ServerAlias directives of the appropriate VirtualHost and if of course those 2 names resolve by dns to your apache server, there is no need to use rewrites.


Quote:

2) The error log messages are like this one:

[Wed Mar 28 11:20:03 2018] [error] [client 201.6.232.101] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/html/multisites/www/cgi-multisites/ezformmx.cgi
This log entry does not give a 404 (Not Found) error, so there must be something else.

If apache thinks that FollowSymLinks is off, then most likely it does not read .htaccess. You can use either one of the following:
Code:

AllowOverride Options
AllowOverride ALL

restart apache and see what you get.

Mario Lima 03-28-2018 01:12 PM

Hi, bathory,

Based in your comments, I reviewed all the lines and I found two inconsistences. I altered and now it is all working, the .htaccess rules as well as the CGI scripts. The inconsistences were:

Error:

<IfModule mod_rewrite.c>
aRewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule (.*) http://www.corretoresdeseguros.com.br/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule (.*) http://corretoresdeseguros.com.br/$1 [R=301,L]
RewriteEngine on
rewritecond %{http_host} ^corretoresdeseguros.com.br [nc]
rewriterule ^(.*)$ http://www.corretoresdeseguros.com.br/$1 [r=301,nc]
Options +FollowSymlinks
</IfModule>

Fixed:

<IfModule mod_rewrite.c>
RewriteEngine off
RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule ^/(.*) http://www.multisites.com.br/$1
RewriteCond %{HTTP_HOST} ^multisites\.com\.br$ [nc]
RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule (.*) http://multisites.com.br/$1 [R=301,L]
rewritecond %{http_host} ^multisites.com.br [nc]
rewriterule ^(.*)$ http://www.multisites.com.br/$1 [r=301,nc]
Options +FollowSymlinks
</IfModule>

Thanks a lot.

Mario Lima 03-28-2018 01:13 PM

The other also fixed:

<IfModule mod_rewrite.c>
RewriteEngine off
RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule ^/(.*) http://www.corretoresdeseguros.com.br/$1
RewriteCond %{HTTP_HOST} ^corretoresdeseguros\.com\.br$ [nc]
RewriteCond %{HTTP_HOST} ^66\.226\.75\.86
RewriteRule (.*) http://corretoresdeseguros.com.br/$1 [R=301,L]
rewritecond %{http_host} ^corretoresdeseguros.com.br [nc]
rewriterule ^(.*)$ http://www.corretoresdeseguros.com.br/$1 [r=301,nc]
Options +FollowSymlinks
</IfModule>

bathory 03-29-2018 12:29 AM

Quote:

Fixed:

<IfModule mod_rewrite.c>
RewriteEngine off
<snip>

The other also fixed:

<IfModule mod_rewrite.c>
RewriteEngine off
<snip>
So, actually you turned off mod_rewrite. I told you that you don't need it in your case.
Anyway, I'm glad you made it.

Cheers

Mario Lima 03-29-2018 06:12 AM

Hi, bathory,

Sure. I thank you very much.

Mário./


All times are GMT -5. The time now is 04:59 PM.