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
<VirtualHost *:80>
ServerName 1.2.3.4:80
#Redirect permanent / https://1.2.3.4/
</VirtualHost>
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:
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:
- The answer states:
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
- The API approves:
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