我正在我的.htaccess文件中使用以下代码重定向应用程序,该页面应该执行以下操作:
扩展名.html工作正常,它从http重定向到https但问题是从www重定向到非www,它在主URL上正常工作但是当有文件引用时它不是工作
当我写www.ntestechnologies.com时,我得到了我的愿望网址https://ntestechnologies.com但是当我写www.ntestechnologies.com/index.html时,我得到了https://www.ntestechnologies.com/index.html我不需要这个网址中的www也请指导我,这是htaccess文件中的代码:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.ntestechnologies\.com$
RewriteRule ^/?$ "https\:\/\/ntestechnologies\.com\/$1" [R=301,L]
RewriteRule ^(.*)\.html$ $1.php [nc]
答案 0 :(得分:1)
您只需要一个RewriteEngine On
。
您无法在HTTP_HOST
中使用REQUEST_URI
或RewriteRule
。如果您需要捕获这些值,则必须在RewriteCond
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(.+)
RewriteRule .* https://%1/$0 [R,L]
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule .* https://%1/$0 [R,L]
这将删除前导www
(如果存在)。同时,它会重定向到HTTPS。
答案 1 :(得分:0)
RewriteEngine On
# Redirects from HTTP to HTTPS. We use %{SERVER_PORT} as it's more reliable than %{HTTPS}
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Redirects www.example.com/... to example.com/...
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule .* https://%1%{REQUEST_URI} [R,L]
RewriteRule ^(.*)\.html$ $1.php [nc]