【问题标题】:apache RewriteRule redirect a page to root not workingapache RewriteRule 将页面重定向到 root 不起作用
【发布时间】:2012-09-24 12:07:27
【问题描述】:

我正在为一个非常简单的 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 保持不变。

这是我完整的配置文件,enseignement2.conf在/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>

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

它在 CentOS 6 上运行,带有 Apache/2.2.22 欢迎大家提出建议,谢谢!

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 2014-08-17
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多