簡體   English   中英

vHost重定向根本不起作用

[英]vHost redirect not working at all

目標:除了RewriteCond中列出的文件和文件夾(及其內容)以外,將每個請求都重定向到index.php。

一位朋友確實和我一起設置了服務器,但是還沒有時間修復此錯誤。 該頁面自動以HTTPS結尾。

當使用它作為000-default.conf(/etc/apache2/sites-enabled/000-default.conf)時,頁面不會重定向到index.php。 例如:訪問www.page.com/uploads/38可以,盡管它應該重定向到www.page.com/index.php。 這很令人討厭,因為我正在模擬文件系統,並且不想允許訪問文件,至少不是那樣。

a2ensite 000-default.conf:網站000-default.conf已啟用a2enmod重寫:模塊重寫已啟用

這是我的000-default.conf:

<VirtualHost *:80>
  ServerAdmin root@page.com
  DocumentRoot /var/www/default
  ServerName www.page.com
  ServerAlias page.com
  RewriteEngine On
  <Location />
    RewriteBase /
    Options -Indexes
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^(index\.php|css|fonts|gfx|js|favicon\.ico)
    RewriteRule ^(.*)$ index.php [L,QSA]
  </Location>
  LogLevel warn
  ErrorLog ${APACHE_LOG_DIR}/default_error.log
  CustomLog ${APACHE_LOG_DIR}/default_access.log combined
</VirtualHost>

<VirtualHost *:443>
  ServerAdmin root@page.com
  DocumentRoot /var/www/default
  ServerName www.page.com
  ServerAlias page.com
  RewriteEngine On
  <Location />
    RewriteBase /
    Options -Indexes
    Options +FollowSymlinks
    RewriteCond %{REQUEST_URI} !^(index\.php|css|fonts|gfx|js|favicon\.ico)
    RewriteRule ^(.*)$ index.php [L,QSA]
  </Location>
  LogLevel warn
  ErrorLog ${APACHE_LOG_DIR}/default_error.log
  CustomLog ${APACHE_LOG_DIR}/default_access.log combined

  SSLEngine on
  SSLCertificateFile      /etc/ssl/page.com.crt
  SSLCertificateKeyFile   /etc/ssl/page.com.key
  SSLCertificateChainFile /etc/ssl/comodo-ca.crt
</VirtualHost>

在查看default_error.log時,我經常會發現如下內容:

Request exceeded the limit of 10 internal redirects due to probable configuration error.

並且:

RSA server certificate CommonName (CN) `page.com' does NOT match server name!?

提前致謝。

%{REQUEST_URI}變量以/開頭,您的正則表達式並不總是這樣,所以該條件將始終為true,包括當URI被重寫為/index.php ,這會導致循環。

將塊替換為:

RewriteBase /
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteCond $1 !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^(.*)$ index.php [L,QSA]

此外,我猜您是購買了名稱為“ page.com” 而不是 “ www.page.com”的證書,這意味着當您轉到“ www.page.com”時,瀏覽器會看到“ page.com”,它將引發異常。 您需要“ www.page.com”(以及(可選)“ page.com”作為備用名稱)/的證書。


編輯

嗯,這在<Location />容器中對我都不起作用。 但這本身在容器之外起作用:

RewriteEngine On

RewriteCond $1 !^(index\.php|css|fonts|gfx|js|favicon\.ico)
RewriteRule ^/(.*)$ /index.php [L,R]

暫無
暫無

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

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