Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache vHost重定向根本不起作用_Apache_.htaccess_Redirect_Vhosts - Fatal编程技术网

Apache vHost重定向根本不起作用

Apache vHost重定向根本不起作用,apache,.htaccess,redirect,vhosts,Apache,.htaccess,Redirect,Vhosts,目标:将每个请求重定向到index.php,但RewriteCond中列出的文件和文件夹(及其内容)除外 一个朋友确实和我一起安装了服务器,但还没有时间修复这个错误。页面自动以HTTPS结尾 将其用作000-default.conf(/etc/apache2/sites enabled/000 default.conf)时,页面不会重定向到index.php。例如:访问www.page.com/uploads/38是可行的,尽管它应该重定向到www.page.com/index.php。这很烦人

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

一个朋友确实和我一起安装了服务器,但还没有时间修复这个错误。页面自动以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>
而且:

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

提前感谢。

变量
%{REQUEST\u 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]
此外,我猜您购买了名为“page.com”的证书,而不是“www.page.com”,这意味着当您转到“www.page.com”,浏览器看到“page.com”的证书时,它将抛出异常。您需要“www.page.com”的证书(可选“page.com”作为备用名称)/


编辑

嗯,这在
容器中对我也不起作用。但这在容器外部单独起作用:

RewriteEngine On

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

我现在使用了$1(我们之前已经这样做了,然后测试了%{REQUEST_URI}并重新启动了Apache。仍然是同样的问题,我仍然能够访问page.com/uploads/38(我最终在)。@Lutan Oh,你想直接重定向浏览器吗?然后你需要使用方括号中的
R
标志:
[L,R]/code>或
[L,R=301]
用于永久重定向。我测试了[L,R]和[L,R=301]并重新启动了apache(/etc/init.d/apache2 restart),但仍然不工作……我将其更改为您的编辑,现在它重定向。剩下的一个问题是:在进行服务器重置之前,我使用了模拟路径和请求URI(page.com/Lutan/test/stuff.txt在运行index.php时将/Lutan/test/stuff.txt输出为REQUEST_URI)以显示特定数据。它也没有更改url。是否有一种简单的方法(或类似的方法)来执行此操作?@Lutan a重定向是一个全新的请求,因此浏览器最初请求的内容都会丢失。
RewriteEngine On

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