HTAccess Mod_Rewrite HTTPS WWW 保持 URL
HTAccess Mod_Rewrite HTTPS WWW Keeping URL
我希望这里有人能够帮助我,因为我正在慢慢失去理智试图让重写规则在 HTAccess 中工作。
我只需要发生 3 件事。
1) 所有 www.流量应该去非 www.
2) 所有非 https 流量都应该转到 https。
3) 所有 URL 都应该通过这些重写得到保留。
我已经在网上尝试了无数不同的例子(以及我自己对它们的混蛋变体),但没有达到我想要的结果。该网站使用 Joomla,因此 Joomla 包含相当多的废话作为标准,但我很确定 none 会干扰它。
使用当前的 HTAccess,'www.' 被删除,用户被迫使用 https,但 URL 正在丢失。
在此先感谢您的协助!
我的 HTAccess 文件在这里:
AddHandler application/x-httpd-php53 .php
ErrorDocument 401 "Authorisation Required"
##
# Joomla Crap START
##
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteBase /
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##
# Joomla Crap END
##
# rewrite www.mywebsite.co.uk > mywebsite.co.uk
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
# rewrite http > https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Redirect 301 /~fitspace https://mywebsite.co.uk
RedirectMatch 301 ^/index.php/(.*)$ https://mywebsite.co.uk/
尝试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
以上规则将重定向
至
和
至
我希望这里有人能够帮助我,因为我正在慢慢失去理智试图让重写规则在 HTAccess 中工作。
我只需要发生 3 件事。
1) 所有 www.流量应该去非 www.
2) 所有非 https 流量都应该转到 https。
3) 所有 URL 都应该通过这些重写得到保留。
我已经在网上尝试了无数不同的例子(以及我自己对它们的混蛋变体),但没有达到我想要的结果。该网站使用 Joomla,因此 Joomla 包含相当多的废话作为标准,但我很确定 none 会干扰它。
使用当前的 HTAccess,'www.' 被删除,用户被迫使用 https,但 URL 正在丢失。
在此先感谢您的协助!
我的 HTAccess 文件在这里:
AddHandler application/x-httpd-php53 .php
ErrorDocument 401 "Authorisation Required"
##
# Joomla Crap START
##
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteBase /
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##
# Joomla Crap END
##
# rewrite www.mywebsite.co.uk > mywebsite.co.uk
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/ [R=301,L]
# rewrite http > https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Redirect 301 /~fitspace https://mywebsite.co.uk
RedirectMatch 301 ^/index.php/(.*)$ https://mywebsite.co.uk/
尝试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
以上规则将重定向
至
和
至