apache RewriteRule将页面重定向到root无法正常工作

时间:2012-10-03 14:26:12

标签: apache tomcat mod-rewrite http-status-code-301

我正在使用一个非常简单的apache重写规则几个小时。它必须如此明显,以至于我再也看不到它了。

作为输入,我进入浏览器:

http://enseignement2.be/deployment.html

我尝试显示此页面:

http://enseignement2.be/hello.html

所以,我在apache conf文件中添加了该规则:

RewriteRule ^deployment\.html$ hello.html [L,NC,QSA,R=301]

......实际上还有很多其他变种。 因此,它会显示deployment.html页面。浏览器的URL保持不变。

这是我在/etc/httpd/conf.d /

中的完整配置文件enseignement2.conf
 <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>

考虑到ProxyPass,因为如果我注释了ProxyPass /deployment.html!行,页面就不再显示了(请求被转移到apache后面的tomcat 7实例。

它运行在CentOS 6上,使用Apache / 2.2.22 欢迎任何建议,谢谢!

1 个答案:

答案 0 :(得分:0)

在server / vhost配置中,您需要在正则表达式中使用前导斜杠:

RewriteRule ^/deployment\.html$ hello.html [L,NC,QSA,R=301]