我处理这种情况已有一段时间了,我以自己想要的方式来解决问题。但是,我的解决方案存在此问题。
最初的问题是使htaccess将所有请求重定向到HTTPS和www前缀的URL,但不包括以“ sitename / api /”开头的请求。我的解决方案目前仅能正常运行,但是来自HTTP URL的请求将重定向到HTTPS,从而删除任何尾随路径并将其替换为“ index.php”。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ index.php [L]
#Pages Redirect
Redirect /page/faqs https://www.sitename.com/faqs
Redirect /page/about https://www.sitename.com/about
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_URI} ^/api(.*)$ [NC]
RewriteRule (.*) ^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteRule ^(.*)$ https://www.sitename.com/$1 [L,R=301,NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
SetEnv TZ Africa/Lagos
</IfModule>
Options -Indexes
<Files .env>
order allow,deny
Deny from all
</Files>
<IfModule php5_module>
php_flag asp_tags Off
php_flag display_errors Off
php_value max_execution_time 960
php_value max_input_time 1920
php_value max_input_vars 16000
php_value memory_limit 16384M
php_value post_max_size 384M
php_value session.gc_maxlifetime 2880
php_value upload_max_filesize 64M
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-php56” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
我希望输入以下URL:
URL: http://sitename.com/rovers
它应该产生以下结果:
URL: https://www.sitename.com/rovers
但是当前结果如下:
URL: https://www.sitename.com/index.php