[英].htaccess not working while accessed via SSL/HTTPS in Apache2
我對.htaccess配置有問題。 我的網絡服務器是Apache2,我的網站是用PHP編碼的。 但是,.htaccess有一些麻煩。
當我通過非SSL( http://mywebsite.dev )訪問它時,我的.htaccess是有效的。 我使用.htaccess進行URL重寫,並通過自定義模板處理錯誤。 但是,當我通過SSL( https://mywebsite.dev )訪問它時,“索引”頁面正常工作。 但是,當我訪問https://mywebsite.dev/page/about時 ,它顯示404 Not Found(顯示默認的404 Not Found頁面,而不是我的自定義頁面。這意味着,我的.htaccess代碼未加載)。
對於我的URL結構,它是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 webmaster@localhost
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
我正在使用Laragon在Windows中開發它。 對於生產環境,它是:Ubuntu 16,PHP 7和Apache2。 謝謝。
對不起,語法錯誤,或者您不明白我的意思。 非常感謝您閱讀我的問題:)
<VirtualHost *:80>
告訴apache,此配置僅適用於所有接口( *
)上的流量,但僅適用於端口80( :80
)上的流量。 由於AllowOverride All
不匹配,因此不會應用於https(端口443)。
要解決此問題,您需要另一個虛擬主機<VirtualHost *:443>
。 您可以在兩個虛擬主機中復制內容,也可以使用包含,請參閱此服務器故障解答 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.