11 edited tags
| link
10 deleted 7865 characters in body
source | link

Then the test user types olddomain.com/testbadlink in the web browser. The logs at nano /var/log/httpd/olddomain_com_requests.log show a 404 error, but there are NO LOGS at nano /var/log/httpd/olddomain_com_error.log.

In case it was a permissions error, root typed chown apache:apache /var/www/html/.htaccess, but the same problem is persisting.

 

Is this an SELinux problem? Or is the syntax of the .htaccess file incorrect? Is there some other possible cause?ANSWER:

 

This is the first time that@garethTheRed got me thinking about .htaccessVirtualHost has been used on this specific server, so there are no previous working conditions fordirectives in the .htaccesshttpd to which to refer on this server.

The complete text of httpd.conf is:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

<Directory "/var/www/html">
    AllowOverride All
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf

ONGOING RESEARCH:


Per @Jasen's requestfiles, I typedwhich ultimately led me to develop the following:

[root@hostname html]# nano /etc/httpd/conf.d/
[root@hostname conf.d]# ls -al
total 40
drwxr-xr-x. 2 root root 4096 Oct  6 19:43 .
drwxr-xr-x. 8 root root 4096 Dec 23  2014 ..
-rw-r--r--. 1 root root 2893 Jul 23  2014 autoindex.conf
-rw-r--r--  1 root root 2110 Nov  3 19:25 hostname.com.conf
-rw-r--r--. 1 root root  366 Jul 23  2014 README
-rw-r--r--. 1 root root 9426 Jul 23  2014 ssl.conf
-rw-r--r--. 1 root root 1252 Jul 23  2014 userdir.conf
-rw-r--r--  1 root root  821 Oct  5 14:48 welcome.conf
[root@hostname conf.d]# nano /etc/httpd/conf.d/hostname.com.conf

The resulting contents are answer, which works and now solves the problem:

<VirtualHost *:443>
    ServerName www.hostname.com
    ServerAlias hostname.com
    ErrorLog /var/log/httpd/hostname_com_error.log
    CustomLog /var/log/httpd/hostname_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://server.ip.addr:8009/
    ProxyPassReverse / ajp://server.ip.addr:8009/
</VirtualHost>

Listen 444

<VirtualHost *:444>
    ServerName www.hostname.com
    ServerAlias hostname.com
    ErrorLog /var/log/httpd/hostname_com_error.log
    CustomLog /var/log/httpd/hostname_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://server.ip.addr:8010/
    ProxyPassReverse / ajp://server.ip.addr:8010/
</VirtualHost>

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    ProxyPass /RedirectMatch ajp://server.ip^(.addr:8011/
    ProxyPassReverse /*)$ ajp://server.ip.addrhttp:8011/
</VirtualHost>

<VirtualHost www.newdomain.com:80>
    ServerName www.newdomain.com
    ServerAlias newdomain.com
    ErrorLog /var/log/httpd/newdomain_com_error.log
    CustomLog /var/log/httpd/newdomain_com_requests.log combined
    ProxyPass / ajp://server.ip.addr:8012/
    ProxyPassReverse / ajp://server.ip.addr:8012/
</VirtualHost>

<VirtualHost www.anotherdomain.com:80>
    ServerName www.anotherdomain.com
    ServerAlias anotherdomain.com
    ErrorLog /var/log/httpd/anotherdomain_com_error.log
    CustomLog /var/log/httpd/anotherdomain_com_requests.log combined
    ProxyPass / ajp://server.ip.addr:8013/
    ProxyPassReverse / ajp://server.ip.addr:8013/
</VirtualHost>

Note that I am waiting to comment out the VirtualHost block for olddomain.com until I can get .htaccess to handle all the redirects of all possible url patterns in olddomain.com/everypossibleurl. For now, olddomain.com is serving up a war that has individual redirects from each and every old url in olddomain.com, which is very inefficient. I want .htaccess to do the job so that the server no longer has to serve up a war for olddomain.com.

As per @garethTheRed's suggestion, I recreated the trigger by typing olddomain.com/badlink in a client web browser, and then tried nano /var/log/httpd/olddomain_com_error.log but found that the file is completely empty. I next tried nano /var/log/httpd/olddomain_com_requests.log and found the following log record showing a 404:

client.ip.addr - - [11/Nov/2015:14:36:43 -0500] "GET /badlink HTTP/1.1" 404 1008 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"

I am currently reading apache documentation about the rewrite rule at this link because of the following comment from david600130 that I read at this other link:

Using .htaccess files and setting AllowOverride All is not recommended. 
It's better to put the rewrite commands in your Directory section in  
httpd.conf. To enable the rewrite engine in this context, you need to  
set "RewriteEngine On" and "Options FollowSymLinks" must be enabled.  

If this is a better approach for CentOS 7, where do I put RewriteEngine On and Options FollowSymLinks?

Or perhaps thereit is a waymore secure to have the apache config do it without resorting to .htaccess?

Per @garethTheRed's suggestion, I first tried my own new guess by commenting out the VirtualHost directive for olddomain.com, and then typing systemctl restart httpd. This caused requests for olddomain.com to produce a blank page with no error printed in browser.

I then uncommented the VirtualHost directive so that things were back to the state of the OP and confirmed that olddomain.com/badurl gave a 404.

Next, I added the following to httpd.conf:

<Location "/server-info">
    SetHandler server-info
</Location>  

And I typed in systemctl restart httpd before trying olddomain.com.randomurl in the browser again, only to get another 404.

I am not sure howfiles do this than to get the console output in @garethTheRed's answer, but I imagine that he is onallow external access to something, given hisan 1.000 batting averagehtaccess in prior questionsfile.

My guess from the last link in his answer is that I need to change the VirtualHost, which might look something like:

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    RewriteEngine  on
    RewriteBase    "/"
    RewriteRule    "(.*)$"  "ajp://server.ip.addr:8012/$1"  [P]
    ProxyPassReverse "/" ajp://server.ip.addr:8012/
</VirtualHost>  

Should I change the VirtualHost? If so, what is the actual correct syntax to use in this case?

Then the test user types olddomain.com/testbadlink in the web browser. The logs at nano /var/log/httpd/olddomain_com_requests.log show a 404 error, but there are NO LOGS at nano /var/log/httpd/olddomain_com_error.log.

In case it was a permissions error, root typed chown apache:apache /var/www/html/.htaccess, but the same problem is persisting.

Is this an SELinux problem? Or is the syntax of the .htaccess file incorrect? Is there some other possible cause?

This is the first time that .htaccess has been used on this specific server, so there are no previous working conditions for .htaccess to which to refer on this server.

The complete text of httpd.conf is:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

<Directory "/var/www/html">
    AllowOverride All
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf

ONGOING RESEARCH:


Per @Jasen's request, I typed the following:

[root@hostname html]# nano /etc/httpd/conf.d/
[root@hostname conf.d]# ls -al
total 40
drwxr-xr-x. 2 root root 4096 Oct  6 19:43 .
drwxr-xr-x. 8 root root 4096 Dec 23  2014 ..
-rw-r--r--. 1 root root 2893 Jul 23  2014 autoindex.conf
-rw-r--r--  1 root root 2110 Nov  3 19:25 hostname.com.conf
-rw-r--r--. 1 root root  366 Jul 23  2014 README
-rw-r--r--. 1 root root 9426 Jul 23  2014 ssl.conf
-rw-r--r--. 1 root root 1252 Jul 23  2014 userdir.conf
-rw-r--r--  1 root root  821 Oct  5 14:48 welcome.conf
[root@hostname conf.d]# nano /etc/httpd/conf.d/hostname.com.conf

The resulting contents are:

<VirtualHost *:443>
    ServerName www.hostname.com
    ServerAlias hostname.com
    ErrorLog /var/log/httpd/hostname_com_error.log
    CustomLog /var/log/httpd/hostname_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://server.ip.addr:8009/
    ProxyPassReverse / ajp://server.ip.addr:8009/
</VirtualHost>

Listen 444

<VirtualHost *:444>
    ServerName www.hostname.com
    ServerAlias hostname.com
    ErrorLog /var/log/httpd/hostname_com_error.log
    CustomLog /var/log/httpd/hostname_com_requests.log combined
    SSLEngine on
    SSLProxyEngine on
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    ProxyPass / ajp://server.ip.addr:8010/
    ProxyPassReverse / ajp://server.ip.addr:8010/
</VirtualHost>

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    ProxyPass / ajp://server.ip.addr:8011/
    ProxyPassReverse / ajp://server.ip.addr:8011/
</VirtualHost>

<VirtualHost www.newdomain.com:80>
    ServerName www.newdomain.com
    ServerAlias newdomain.com
    ErrorLog /var/log/httpd/newdomain_com_error.log
    CustomLog /var/log/httpd/newdomain_com_requests.log combined
    ProxyPass / ajp://server.ip.addr:8012/
    ProxyPassReverse / ajp://server.ip.addr:8012/
</VirtualHost>

<VirtualHost www.anotherdomain.com:80>
    ServerName www.anotherdomain.com
    ServerAlias anotherdomain.com
    ErrorLog /var/log/httpd/anotherdomain_com_error.log
    CustomLog /var/log/httpd/anotherdomain_com_requests.log combined
    ProxyPass / ajp://server.ip.addr:8013/
    ProxyPassReverse / ajp://server.ip.addr:8013/
</VirtualHost>

Note that I am waiting to comment out the VirtualHost block for olddomain.com until I can get .htaccess to handle all the redirects of all possible url patterns in olddomain.com/everypossibleurl. For now, olddomain.com is serving up a war that has individual redirects from each and every old url in olddomain.com, which is very inefficient. I want .htaccess to do the job so that the server no longer has to serve up a war for olddomain.com.

As per @garethTheRed's suggestion, I recreated the trigger by typing olddomain.com/badlink in a client web browser, and then tried nano /var/log/httpd/olddomain_com_error.log but found that the file is completely empty. I next tried nano /var/log/httpd/olddomain_com_requests.log and found the following log record showing a 404:

client.ip.addr - - [11/Nov/2015:14:36:43 -0500] "GET /badlink HTTP/1.1" 404 1008 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"

I am currently reading apache documentation about the rewrite rule at this link because of the following comment from david600130 that I read at this other link:

Using .htaccess files and setting AllowOverride All is not recommended. 
It's better to put the rewrite commands in your Directory section in  
httpd.conf. To enable the rewrite engine in this context, you need to  
set "RewriteEngine On" and "Options FollowSymLinks" must be enabled.  

If this is a better approach for CentOS 7, where do I put RewriteEngine On and Options FollowSymLinks?

Or perhaps there is a way to have the apache config do it without resorting to .htaccess?

Per @garethTheRed's suggestion, I first tried my own new guess by commenting out the VirtualHost directive for olddomain.com, and then typing systemctl restart httpd. This caused requests for olddomain.com to produce a blank page with no error printed in browser.

I then uncommented the VirtualHost directive so that things were back to the state of the OP and confirmed that olddomain.com/badurl gave a 404.

Next, I added the following to httpd.conf:

<Location "/server-info">
    SetHandler server-info
</Location>  

And I typed in systemctl restart httpd before trying olddomain.com.randomurl in the browser again, only to get another 404.

I am not sure how to get the console output in @garethTheRed's answer, but I imagine that he is on to something, given his 1.000 batting average in prior questions.

My guess from the last link in his answer is that I need to change the VirtualHost, which might look something like:

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    RewriteEngine  on
    RewriteBase    "/"
    RewriteRule    "(.*)$"  "ajp://server.ip.addr:8012/$1"  [P]
    ProxyPassReverse "/" ajp://server.ip.addr:8012/
</VirtualHost>  

Should I change the VirtualHost? If so, what is the actual correct syntax to use in this case?

Then the test user types olddomain.com/testbadlink in the web browser. The logs at nano /var/log/httpd/olddomain_com_requests.log show a 404 error.

 

ANSWER:

 

@garethTheRed got me thinking about VirtualHost directives in the httpd conf files, which ultimately led me to develop the following answer, which works and now solves the problem:

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    RedirectMatch ^(.*)$ http://newdomain.com
</VirtualHost>  

Note that it is more secure to have the httpd conf files do this than to allow external access to an .htaccess file.

9 added 899 characters in body
source | link

My guess from the last link in his answer is that I need to change the VirtualHost, which might look something like:

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    RewriteEngine  on
    RewriteBase    "/"
    RewriteRule    "(.*)$"  "ajp://server.ip.addr:8012/$1"  [P]
    ProxyPassReverse "/" ajp://server.ip.addr:8012/
</VirtualHost>  

Should I change the VirtualHost? If so, what is the actual correct syntax to use in this case?

My guess from the last link in his answer is that I need to change the VirtualHost, which might look something like:

<VirtualHost www.olddomain.com:80>
    ServerName www.olddomain.com
    ServerAlias olddomain.com
    ErrorLog /var/log/httpd/olddomain_com_error.log
    CustomLog /var/log/httpd/olddomain_com_requests.log combined
    RewriteEngine  on
    RewriteBase    "/"
    RewriteRule    "(.*)$"  "ajp://server.ip.addr:8012/$1"  [P]
    ProxyPassReverse "/" ajp://server.ip.addr:8012/
</VirtualHost>  

Should I change the VirtualHost? If so, what is the actual correct syntax to use in this case?

8 added 899 characters in body
source | link
7 added 82 characters in body
source | link
6 added brief summary of research of a different possible approach.
source | link
5 added 427 characters in body
source | link
4 added 507 characters in body
source | link
3 added 3562 characters in body
source | link
2 added 1540 characters in body
source | link
1
source | link