0
votes

I've been trying to get this up in my .htaccess file for 2days now, but i can't get it to work properly.

I'm working at a company and they need this specific redirects to their website and subdomain because their joomla setup requires it.

all scenarios:

main domain

http://www.my-main.be -> https://www.my-main.be

http://my-main.be -> https://www.my-main.be

https://www.my-main.be -> https://www.my-main.be

https://my-main.be -> https://www.my-main.be

subdomain

http://www.mysub.my-main.be -> http://mysub.my-main.be

http://mysub.my-main.be -> http://mysub.my-main.be

https://www.mysub.my-main.be -> http://mysub.my-main.be

https://mysub.my-main.be -> http://mysub.my-main.be

note:

  • mysub may be fixed, but is prefered dynamic so all the subdomains go to http://.
  • It is important to have www in the main domain
  • It is important to have www left out of the subdomain

Is this possible?

Leave a comment if i did not explain this well enough and i will clarify it more.

Thanks in advance

2
Are DocumentRoot for main domain and subdomain pointing to same location? - anubhava
Yes, there is only one instance of joomla installed - Jonas S'jegers
can you show your existing .htaccess in question - anubhava
I changed it alot in the past two days. the latest version i have now is not even close to working. but i might post it on fiverr as well, because it has to be ready soon - Jonas S'jegers
There is no stable version anymore. at the moment all links get redirected to https//www because that's the only way the main website works now. We have 100+ orders/day on the website so i can't be screwing around in it alot. you can see all the scenarios above and if you really need code examples you can see at stackoverflow.com/questions/29088257/… or stackoverflow.com/questions/27882723/… - Jonas S'jegers

2 Answers

0
votes

You can have these rules just below RewriteEngine line:

RewriteEngine On

# for main domain
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(my-main\.be)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

# for sub domain
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(mysub\.my-main\.be)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]

# rest of rules go here

Test it after clearing your browser cache.

0
votes

Please checked rules below both rules will work well with dynamic sub domain also

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www\.)?((.*))$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]