當我在外部打開我的網站時出現錯誤。我收到此錯誤:內部服務器錯誤服務器遇到內部錯誤或配置錯誤,無法完成您的請求。
如果我洗掉我的 .htaccess,它不會給我錯誤,而是向我顯示 /htdocs 的路徑并且我已經配置了一個子檔案夾。
如果我打開 localhost:80 它會正確重定向到子檔案夾 htdocs/folder-name 問題是當我通過www.domain.com externaly 打開它時。
這是我的.htaccess。路徑:C:\Apache24\htdocs.htaccess 內容:
#DON'T SHOW DIRECTORY LISTINGS
Options -Indexes
#FOLLOW SYMBOLIC LINKS
Options FollowSymLinks
#SET DEFAULT HANDLER
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^DOMAIN.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.DOMAIN.com$
RewriteCond %{REQUEST_URI} !FOLDER/
RewriteRule (.*) /FOLDER/$1 [L]
#ERROR 404 PAGE
ErrorDocument 404 /404.html
阿帕奇日志:
client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/
[AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var
AH01797: client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/favicon.ico, referer: https://www.example.com/
AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var, referer: https://www.example.com/
** 重寫模塊處于活動狀態且路徑正確 **
VirtualHost的httpd.conf代碼
編輯
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
**** 使用新的 HTTPD.CONF 進行編輯 ****
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
Redirect 301 / https://example.com/
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =example.com [OR]
# RewriteCond %{SERVER_NAME} =www.example.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
````
uj5u.com熱心網友回復:
<VirtualHost *:80> : DocumentRoot C:\Apache24\htdocs\example : <VirtualHost *:443> : DocumentRoot C:\Apache24\htdocs\Mymxtools
DocumentRoot令人困惑的是,您為兩個 VirtualHost定義了不同的。(也許這是您的示例中的錯誤?)盡管您將所有內容都重定向到 HTTPS,所以這并不重要,因為它發生了。
但是,您沒有“允許”訪問檔案系統的這一部分或啟用.htaccess覆寫。
您需要在容器中使用類似以下的<VirtualHost *:443>內容來授予訪問權限并啟用.htaccess覆寫。
<Directory C:\Apache24\htdocs\Mymxtools>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
在旁邊:
RewriteEngine on RewriteCond %{SERVER_NAME} =example.com [OR] RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
要將<VirtualHost *:80>容器中的所有內容從 HTTP 重定向到 HTTPS,您不需要這個“復雜”的 mod_rewrite 規則。一個更簡單的 mod_aliasRedirect就足夠了(并且是首選)。
例如,改用以下內容:
Redirect 301 / https://example.com/
您應該在此階段規范化主機名。您之前的 mod_rewrite 規則將保留主機名,即。www 或非 www。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/473503.html
上一篇:如何重寫導致重復內容的URL?
