0

我为一个非常简单的 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 欢迎任何建议,谢谢!

4

1 回答 1

0

在服务器/虚拟主机配置中,您的正则表达式中需要一个前导斜杠:

RewriteRule ^/deployment\.html$ hello.html [L,NC,QSA,R=301]
于 2012-10-03T18:19:50.053 回答