簡體   English   中英

網站僅在前面使用index.php

[英]Website only working with index.php in front

我在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]

我還使用了文檔中提供的配置:

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知道當瀏覽器請求基地址時,Apache可以為該文件提供服務。

如果不想將服務器配置為允許.htaccess文件,則可以更改站點的httpd.conf文件:

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

暫無
暫無

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

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