我遇到了.htaccess配置問題。我的網絡服務器是Apache2,我的網站由PHP編碼。但是,我在.htaccess中遇到了一些麻煩。.htaccess在通過Apache2中的SSL/HTTPS訪問時無法正常工作
雖然我通過非ssl訪問它(http://mywebsite.dev),但我的.htaccess是工作的。我使用.htaccess進行URL重寫並通過自定義模板處理錯誤。但是,當我通過SSL(https://mywebsite.dev)訪問它時,對於索引頁是行得通的。但是,當我訪問https://mywebsite.dev/page/about時,它顯示404 Not Found(顯示默認的404 Not Found頁面,而不是我的自定義頁面。這意味着我的.htaccess代碼沒有加載)。
對於我的網址結構,它是http://mywebsite.dev/?load=page&page=about。如果我訪問http://mywebsite.dev/page/about,它可以工作。但是,不通過SSL。什麼是問題?順便說一句,我的/etc/apache2/sites-available/website.conf代碼:
<VirtualHost *:80>
ServerName mydomain.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/website/
<Directory /var/www/html/website>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# enabled or disabled at a global level, it is possible to
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
而且,我的.htaccess代碼:
RewriteEngine On
RewriteRule ^page/([A-Za-z0-9-]+)/?$ index.php?load=page&page=$1 [NC]
ErrorDocument 404 /public/404.html
我在Windows中使用Laragon開發它。生產環境是:Ubuntu 16,PHP 7和Apache2。謝謝。
對不起語法錯誤,或者你不明白我的意思。非常感謝你閱讀我的問題:)
你的意思是,我需要用不同的端口創建新的虛擬主機,通過https處理請求,我錯了嗎? CMIIW。感謝您的迴應。 – filosofikode
對,你需要兩個虛擬主機來處理http和https(服務器故障問題就是這樣)。如果你可以通過https訪問你的服務器,你已經有一個'SSLEngine on'(和其他'SSLCertificateFile'),你可能需要修改/重用它。 –