Wednesday, October 8, 2014

apache 2.4 - Mod_rewrite rule to redirect from a specific path to another is completely ignored

I need to redirect http://1.2.3.4/foo to http://1.2.3.4/WebFOO. The rule that I've created looks like this in ApacheRoot\conf\httpd.conf:



RewriteEngine On
RewriteRule ^/?foo /WebFOO [R,L]



However, this approach doesn't work even though this rule is syntactically correct. Means I connect to http://1.2.3.4/foo and get a 404 or the specific content for "/foo". Note: to test things out I've created a folder with a simple index.html in (htdocs/foo). This actually prevented the 404 of course but still the redirection did not take place.



The virtual-host portion looks like this and is beneath the mod-rewrite rule:



ServerName 1.2.3.4

ServerName 1.2.3.4:80
#Redirect permanent / https://1.2.3.4/




Why is that redirection completely ignored? Am I able to check somehow whether the server at least recognizes the rule (no rewrite-entries so far in the error.log)?



Note: To be sure about the syntactical correctness of the rule I've also tested it with http://htaccess.madewithlove.be:



Rewrite rule tester result



Not only this test worked fine but also things like /foo/index.html. It was correctly translated into /WebFOO/index.html.




Note: Enabling the verbose logging as suggested by one of a mod_rewrite canonical question's answer is not suitable for apache 2.4:






For more complex rules, use mod_rewrite's RewriteLog directive to log
activity to a file and set RewriteLogLevel 3








Since Apache httpd 2.4 mod_rewrite RewriteLog and RewriteLogLevel
directives has been completely replaced by the new per-module logging
configuration.



LogLevel alert rewrite:trace6








RewriteLog



Those familiar with earlier versions of mod_rewrite will no doubt be
looking for the RewriteLog and RewriteLogLevel directives. This
functionality has been completely replaced by the new per-module
logging configuration mentioned above. To get just the
mod_rewrite-specific log messages, pipe the log file through grep:
tail -f error_log|fgrep '[rewrite:'






  • I don't have any [rewrite: entries in my ApacheRoot\logs\error.log

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...