LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-03-2016, 07:27 PM   #1
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
Apache2 RewriteCond not working, no log


Hi group,
I am attempting to configure my Apache web server to redirect any traffic for one IP to another IP. I have three IP addresses 10.1.1.12, 10.1.1.13 and 10.1.1.56. 12 and 13 are running on the same Raspberry Pi, running Raspbian. I'm using the Rewrite option of Apache with the following configuration:
Code:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

  RewriteEngine On
  RewriteLog "/var/log/apache2/rewrite.log" 
  RewriteLogLevel 5
 
  RewriteCond %{SERVER_ADDR} ^10.1.1.13
  RewriteRule .* http://10.1.1.56/%(REQUEST_URI) [R=301,L]
Using this command:
Code:
apache2ctl -M
[Tue Apr 26 01:25:25 2016] [warn] module rewrite_module is already loaded, skipping
[Tue Apr 26 01:25:25 2016] [warn] module info_module is already loaded, skipping
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)
 info_module (shared)
Syntax OK
I can see that the rewrite module is being loaded. When I attempt 'wget 10.1.1.13', I get the index.html for 10.1.1.12 and nothing in the rewrite.log.

What am I missing?
 
Old 05-04-2016, 04:30 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
Hi,

A couple of things:
You load twice mod_rewrite (and info_module if it matters).
Quote:
RewriteRule .* http://10.1.1.56/%(REQUEST_URI) [R=301,L]
You have an error in the RewriteRule. Replace %(REQUEST_URI) with %{REQUEST_URI}

Quote:
When I attempt 'wget 10.1.1.13', I get the index.html for 10.1.1.12 and nothing in the rewrite.log.
Rewrite should work. Since you're getting 10.1.1.12 instead of 10.1.1.56 or the initial 10.1.1.13, it could be a browser cache problem, so clear your browser cache before testing, or start a new session.
Re. logging it should work also,
I guess you're running apache-2.2.x, because RewriteLog is dropped in the new apache-2.4.x. So make sure that you restart apache after editing the config file(s)

Regards
 
Old 05-04-2016, 02:44 PM   #3
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by bathory View Post
Hi,

A couple of things:
You load twice mod_rewrite (and info_module if it matters).

You have an error in the RewriteRule. Replace %(REQUEST_URI) with %{REQUEST_URI}


Rewrite should work. Since you're getting 10.1.1.12 instead of 10.1.1.56 or the initial 10.1.1.13, it could be a browser cache problem, so clear your browser cache before testing, or start a new session.
Re. logging it should work also,
I guess you're running apache-2.2.x, because RewriteLog is dropped in the new apache-2.4.x. So make sure that you restart apache after editing the config file(s)

Regards
Thanks for the reply.
  • Your right about the loaded modules, don't think that is a problem, but commented out my loading.
  • Not a caching problem ( I believe ), using wget.
  • Changed '(' to '}', no effect..
  • Used "service apache2 restart" after making changes.
    Code:
    root:~; service apache2 restart
    [....] Restarting web server: apache2[Tue Apr 26 20:30:06 2016] [warn] module info_module is already loaded, skipping
     ... waiting .[Tue Apr 26 20:30:09 2016] [warn] module info_module is already loaded, skipping
    . ok
From Apache log on 10.1.1.12/13:
Code:
10.1.1.56 - - [26/Apr/2016:20:30:33 -0700] "GET /Test.php HTTP/1.1" 200 110052 "-" "Wget/1.16.3 (linux-gnu)"
From the error log:
Code:
tail  /var/log/apache2/error.log
[Tue Apr 26 20:29:44 2016] [notice] caught SIGTERM, shutting down
[Tue Apr 26 20:29:46 2016] [warn] module rewrite_module is already loaded, skipping
[Tue Apr 26 20:29:46 2016] [warn] module info_module is already loaded, skipping
[Tue Apr 26 20:29:47 2016] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u2 configured -- resuming normal operations
[Tue Apr 26 20:30:07 2016] [notice] caught SIGTERM, shutting down
[Tue Apr 26 20:30:09 2016] [warn] module info_module is already loaded, skipping
[Tue Apr 26 20:30:09 2016] [notice] Apache/2.2.22 (Debian) PHP/5.4.45-0+deb7u2 configured -- resuming normal operations
Note: my server has the wrong date:
Code:
root:~; date
Tue Apr 26 20:45:21 PDT 2016
That should not have any effect on this problem.

Any other observation? This should work!
 
Old 05-04-2016, 06:20 PM   #4
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
I changed the host server to my laptop and got it to work with this file:
Code:
  RewriteEngine On
  LogLevel info rewrite:trace1
  RewriteCond %{SERVER_ADDR} ^(10.1.1.57)
  RewriteRule ^.* http://10.1.1.13/%{REQUEST_URI} [R=301,L]
Also added this to my apache2.conf:
Code:
IncludeOptional conf.d/*.conf
The rewrite log entries are in errorlog:
Code:
[Wed May 04 19:10:00.780422 2016] [rewrite:trace1] [pid 4916] mod_rewrite.c(476): [client 10.1.1.57:37532] 10.1.1.57 - - [10.1.1.57/sid#557242b67390][rid#557242c1f9c0/initial] redirect to http://10.1.1.13//Test.php [REDIRECT/301]
Still failing on my R-Pi, raspbian.
 
Old 05-05-2016, 02:45 AM   #5
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:
I changed the host server to my laptop and got it to work with this file:

RewriteEngine On
LogLevel info rewrite:trace1
RewriteCond %{SERVER_ADDR} ^(10.1.1.57)
RewriteRule ^.* http://10.1.1.13/%{REQUEST_URI} [R=301,L]
In the above rule, you use 10.1.1.57 and not 10.1.1.56 as in your OP, so verify the IP you want to redirect
Other than that, I agree that it should work.
 
Old 05-05-2016, 12:47 PM   #6
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by bathory View Post
In the above rule, you use 10.1.1.57 and not 10.1.1.56 as in your OP, so verify the IP you want to redirect
Other than that, I agree that it should work.
All together, I am using 4 IPs on two computers:
  • 10.1.1.12 on my server
  • 10.1.1.13 on my server, used to redirect.
  • 10.1.1.56 on my laptop.
  • 10.1.1.57 on my laptop, used to redirect.
There are two set ups I used to test:
  1. request 10.1.1.13 which is redirected to 10.1.1.56, does not work
  2. request 10.1.1.57 which is redirected to 10.1.1.13, which works.
 
Old 05-05-2016, 04:29 PM   #7
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Original Poster
Rep: Reputation: 40
I got it to work on my web server with this:
Code:
  
  Options +FollowSymLinks
<virtualHost test:80>
  RewriteEngine On
  RewriteLogLevel 1
  RewriteOptions Inherit
  RewriteLog "/var/log/apache2/rewrite.log" 
 
  RewriteCond "%{SERVER_ADDR}" "^10.1.1.13"
  RewriteRule ^.* http://10.1.1.56/%{REQUEST_URI} [R=301,L]
</virtualhost>
I guess the VirtualHost is a requirement for Apache 2.2.xx?

Note: For this example to work, I had to update /etc/hosts with this entry:
Code:
10.1.1.12 test

Last edited by MrUmunhum; 05-07-2016 at 02:16 PM. Reason: add note
 
  


Reply



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
RewriteCond not working compused Linux - Software 9 09-28-2013 10:00 AM
apache2 log output razzera Programming 4 05-11-2010 09:07 AM
apache2 log question razzera Linux - Server 3 05-10-2010 05:14 PM
Doubt about RewriteCond? your_shadow03 Linux - Newbie 8 12-18-2009 03:29 PM
apache2 log jonfa Linux - General 2 09-24-2003 02:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:49 AM.

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