1

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.

All I need is for 3 things to happen.

1) All www. traffic should go to non-www.
2) All non-https traffic should go to https.
3) All URLs should be preserved through these rewrites.

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.

With the current HTAccess the 'www.' is being dropped and the user is forced to https, but the URL is being lost.

Thanks in advance for your assistance!

My HTAccess file is here:

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 

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately this isn't working for me, I'm wondering if the other rules are affecting it. I'll try removing everything and starting from a clean slate.
Thank you!! It's redirecting. I can't work out what it was, but one of the Joomla bits was interfering.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.