簡體   English   中英

apache RewriteRule將頁面重定向到根目錄不起作用

[英]apache RewriteRule redirect a page to root not working

我正在努力用一個非常簡單的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實例。

它運行在帶有Apache / 2.2.22的CentOS 6上,歡迎大家提出任何建議,謝謝!

在服務器/虛擬主機配置中,您需要在正則表達式中加一個斜杠:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM