简体   繁体   English

HTAccess Mod_Rewrite HTTPS WWW保留URL

[英]HTAccess Mod_Rewrite HTTPS WWW Keeping URL

I'm hoping someone here will be able to help me as I'm slowly losing my mind trying to get a rewrite rule working in HTAccess. 我希望这里的某人能够为我提供帮助,因为我逐渐失去了要在HTAccess中使用重写规则的想法。

All I need is for 3 things to happen. 我需要做的是三件事。

1) All www. 1)所有www。 traffic should go to non-www. 流量应转到非www。
2) All non-https traffic should go to https. 2)所有非https流量都应转到https。
3) All URLs should be preserved through these rewrites. 3)应该通过这些重写保留所有URL。

I've tried countless different examples online (and my own bastardised variations on them) without achieving the results I'm after. 我在网上尝试了无数不同的示例(以及我自己的拙劣变体),但没有获得我想要的结果。 The site uses Joomla, so there's a fair amount of crap that Joomla includes as standard, but I'm pretty sure none of that is interfering with it. 该网站使用的是Joomla,因此Joomla包含了很多废话,但我敢肯定,这些都不会对它造成干扰。

With the current HTAccess the 'www.' 使用当前的HTAccess,“ www。” is being dropped and the user is forced to https, but the URL is being lost. 被丢弃,用户被迫使用https,但是URL丢失了。

Thanks in advance for your assistance! 提前感谢你的帮助!

My HTAccess file is here: 我的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}/$1 [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/$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/$1

Try : 尝试:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]

The rule above will redirect 上面的规则将重定向

to

And

to

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM