vHost重定向根本不工作

时间:2015-01-09 01:44:35

标签: apache .htaccess redirect vhosts

目标:将每个请求重定向到index.php,但RewriteCond中列出的文件和文件夹(及其内容)除外。

朋友确实和我一起设置了服务器,但还没有时间修复这个bug。该页面自动以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:已启用Site 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!?

提前致谢。

1 个答案:

答案 0 :(得分:0)

%{REQUEST_URI}变量以/开头,你的正则表达式没有,所以条件总是为真,包括当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]

此外,我猜你已经购买了名称&#34; page.com&#34;,&#34; www.page.com& #34;,这意味着当你去#www.; www.page.com&#34;并且浏览器会看到&#34; page.com&#34;的证书,它会抛出异常。您需要获得&#34; www.page.com&#34; (并且可选择使用&#34; page.com&#34;作为替代名称)/。


修改

嗯,这对<Location />容器内部的工作并不起作用。但这本身就在容器之外起作用了:

RewriteEngine On

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