I'm struggeling with a very simple apache rewrite rule for hours. It must be so obvious that I can't see it anymore.
As input, I enter in the browser:
http://enseignement2.be/deployment.html
I try to have this page being displayed:
http://enseignement2.be/hello.html
So, I added that rule in the apache conf file:
RewriteRule ^deployment\.html$ hello.html [L,NC,QSA,R=301]
... and many other variants actually. As a result, it displays the deployment.html page. The browser's URL remains unchanged.
This is my complete configuration file, enseignement2.conf in /etc/httpd/conf.d/
<VirtualHost 68.169.61.167:80>
ServerName enseignement2.be
DocumentRoot /var/www/hagakure/data/www/
SuexecUserGroup hagakure hagakure
CustomLog /var/www/httpd-logs/enseignement2.be.access.log combined
ErrorLog /var/www/httpd-logs/enseignement2.be.error.log
ServerAlias *.enseignement2.be www.enseignement2.be
AddDefaultCharset UTF-8
# enable expirations
ExpiresActive On
# expire GIF,JPEG,PNG images after a month in the client's cache
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType application/javascript A2592000
ExpiresByType text/css A2592000
RewriteEngine on
# RewriteCond %{HTTP_HOST} ^(.+)\.enseignement(2|deux)\.be [NC] # only if there is something (at lease 1 char) before the first dot. example: toto.enseignement2.be
# RewriteRule ^(.*)?$ http://enseignement2.be$1 [redirect=301,nocase]
RewriteRule ^deployment\.html$ hello.html [L,NC,QSA,R=301]
# Directives for eApps applications dependent on Apache
ProxyPass /deployment.html !
ProxyPass /deployment.jpg !
ProxyPass /hello.html !
ProxyPass /manager/ispmgr !
ProxyPass /manimg !
ProxyPass /mancgi !
ProxyPass /webmail !
ProxyPass /joomla !
ProxyPass /awstats !
ProxyPass /myadmin !
# Directives for your application
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
The ProxyPass are taken into account, because if I comment the line ProxyPass /deployment.html !, the page does not display anymore (the request is transferred to the tomcat 7 instance behind apache.
It runs on CentOS 6, with Apache/2.2.22 Any suggestion is welcome guys, thanks!
In server/vhost config, you need a leading slash in your regex:
RewriteRule ^/deployment\.html$ hello.html [L,NC,QSA,R=301]