我在Red Hat 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]
我还使用了in the documentation提供的配置:
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>
答案 0 :(得分:1)
this answer中介绍了最简单的解决方案。假设您的Apache服务器配置为允许.htaccess
个文件,请编辑与您的站点相对应的文件,以包括以下行:
DirectoryIndex index.php
当客户端通过在目录名称末尾指定
DirectoryIndex
来请求目录索引时,/
指令设置要查找的资源列表。
如果您的.htaccess
文件尚未为index.php
指令列出DirectoryIndex
,则需要添加它以使Apache知道当基地址为时可以为该文件提供服务。浏览器要求。
如果您不想将服务器配置为允许.htaccess
文件,则可以更改站点的httpd.conf
文件:
<Directory /path/to/site/>
DirectoryIndex index.php
</Directory>