【发布时间】:2023-03-20 23:25:01
【问题描述】:
当我使用https://example.com 打开网站时,它会在 URL 中没有 public 的情况下打开,但是当我尝试打开 http://example.com 时,它将重定向到 https://example.com/public,而 URL 中的 public。
我想将http:// 重定向到https://,但网址中没有public。
文件夹结构:
.htaccess 根目录下的文件代码
#disable directory browsing
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>
#PROTECT ENV FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>
# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit -1
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php74"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
php_flag display_errors Off
php_value max_execution_time 30
php_value max_input_time 60
php_value max_input_vars 1000
php_value memory_limit -1
php_value post_max_size 8M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php74"
php_value upload_max_filesize 2M
php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
公共目录下的.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
【问题讨论】:
-
请帮我找出问题所在!
-
您发布的代码中没有 HTTP 到 HTTPS 重定向。你知道这是在哪里触发的吗? (您有权访问服务器配置吗?)重定向中使用的 3xx HTTP 状态代码是什么? “......它将重定向到
https://example.com/public” - 你的意思是/public/(带有斜杠)?还是在重定向后实际上没有斜杠(这很重要)?
标签: laravel .htaccess url-rewriting laravel-8 http-redirect