网站仅在前面使用index.php工作



我在红色帽子Linux服务器上有两个网站;第一个位于var/www中,并在var/www/html/.htaccess上具有以下配置。

Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
  RewriteEngine On
 # Reroute to index.php
  RewriteCond $1 !^(index.php)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>

第二个站点位于var/www/laravel中,其配置文件在var/www/laravel/public/.htaccess中。我尝试使用与第一个站点相同的配置,删除文件,然后使用默认配置列出的:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我还使用了文档中提供的配置:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

我还检查了我的mod_rewrite是否对此命令没有注册:

grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite

是。

第一个网站在没有index.php的情况下运行良好,但是Laravel需要它。关于我做错了什么的暗示?

编辑:那就是我为第二个网站创建别名的方式,也许会有所帮助:

<VirtualHost *:80>
   ServerAdmin example@example.com
   DocumentRoot /var/www/html/
   ServerName www.example.com
   ServerAlias *.example.com
   Alias /laravel /var/www/laravel/public/
   ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/www.example.com-error_log.%y%m%d 86400"
   CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/www.example.com-access_log.%y%m%d 86400" combined
#   php_admin_value upload_tmp_dir "/var/www/html/tmp/"
#   php_admin_value open_basedir "/var/www/html/:/var/cache/www/"
   <Directory /var/www/html/>
      AllowOverride All
   </Directory>
   <Directory /var/www/laravel/public/>
      AllowOverride All
   </Directory>
</VirtualHost>

最简单的解决方案在此答案中涵盖。假设您的Apache服务器配置为允许.htaccess文件,请编辑与您的网站相对应的文件,以包括以下行:

DirectoryIndex index.php

根据apache文档,

DirectoryIndex指令设置要查找的资源列表,当客户端通过在目录名称的末尾指定/来请求目录的索引。

如果您的.htaccess文件尚未列出了DirectoryIndex指令的index.php,则需要添加它以让Apache知道,当您的浏览器请求基本地址时,它可以使用该文件。

>

如果您不想配置服务器以允许.htaccess文件,则可以更改网站的httpd.conf文件:

<Directory /path/to/site/>
    DirectoryIndex index.php
</Directory>

最新更新