LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS
User Name
Password
CentOS This forum is for the discussion of CentOS Linux. Note: This forum does not have any official participation.

Notices


Reply
  Search this Thread
Old 03-27-2018, 08:51 PM   #1
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Rep: Reputation: Disabled
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
 
Old 03-28-2018, 07:27 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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

Last edited by bathory; 03-28-2018 at 07:43 AM. Reason: forgot a word!
 
Old 03-28-2018, 08:01 AM   #3
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Original Poster
Rep: Reputation: Disabled
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./
 
Old 03-28-2018, 08:47 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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.
 
Old 03-28-2018, 09:30 AM   #5
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Original Poster
Rep: Reputation: Disabled
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
 
Old 03-28-2018, 11:59 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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.
 
Old 03-28-2018, 01:12 PM   #7
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-28-2018, 01:13 PM   #8
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Original Poster
Rep: Reputation: Disabled
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>
 
Old 03-29-2018, 12:29 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 03-29-2018, 06:12 AM   #10
Mario Lima
LQ Newbie
 
Registered: Mar 2018
Posts: 22

Original Poster
Rep: Reputation: Disabled
Hi, bathory,

Sure. I thank you very much.

Mário./
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in awk file execution Rizwanamalek Linux - Networking 14 03-26-2015 01:09 PM
targa.c file execution error soni_silver17 Linux - Software 2 04-30-2009 12:41 PM
targa.c file execution error soni_silver17 Linux - Software 3 04-01-2009 09:29 AM
Cgi execution problems zenerdiode Linux - Newbie 4 08-26-2006 09:02 PM
CGI execution problems isuck@linux Linux - Software 6 08-02-2006 05:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > CentOS

All times are GMT -5. The time now is 07:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration