Multiple Of The Same Domain - Redirect

mojo8850

New Member
I swear I'm not advertising here.
I need this fixing how can I do this..

When all the above are typed in the address bar by user I want them all to transfer to
https://www.**********.co.uk

If you think I'm advertising I'll use asterisks if you wish.
 

AsheSkyler

New Member
Nah, don't worry about censoring. I just get suspicious easy since some folks post once and we never see them again.


What I did on my site was something similar to this, right below the "RewriteEngine on" part:

RewriteCond %{http_host} ^stiffnights.co.uk [nc]
RewriteCond %{http_host} ^www.stiffnights.co.uk [nc]
RewriteRule ^(.*)$ https://www.stiffnights.co.uk/ [r=301,nc]

It worked for me and will redirect regardless if the user types in "http://" or not, but I wasn't working with secure pages. You'll definitely want to test it.
I tried looking around for an exact answer, but like all other things related to coding, there is no one standard method.
 

mojo8850

New Member
Thank you skyler..

The links don't redirect to https;//www.stiffnights.co.uk
If I type stiffnights.co.uk it don't redirect

Wonder what it is.
 

AsheSkyler

New Member
The blind leading the blind?

Try this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.stiffnights.co.uk/$1 [R,L]
 

chrishirst

Well-Known Member
Staff member
Ashe's solution will work but take note that if you have any subdomins they will ALSO be redirect to https://www.domain.tld


Also to avoid appearing to be link dropping to your Internet properties, ESPECIALLY ones that are inappropriate for forums such as this, use a dummy name for the domain name.

We do not need the actual name of the domain for a generic question such as this, domain.tld will suffice.
 

chrishirst

Well-Known Member
Staff member
Oh and to prevent auto-linking there is a checkbox under the post editor (full editor NOT the quick post) that says "Automatically parse links in text", by unchecking that it will leave URLs as plain text.
 

mojo8850

New Member
Ok after a little organizing this is my result.

My .htaccess file is as follows:-
DirectoryIndex index.html index.php

# Use PHP5 Single php.ini as default
AddType x-mapp-php5 .php

RewriteEngine On
RewriteCond %{http_host} ^mydomain.co.uk [nc]
RewriteCond %{http_host} ^mydomain.co.uk [nc]
RewriteRule ^(.*)$ https://www.mydomain.co.uk/ [r=301,nc]
RewriteCond %{SERVER_PORT} 443

Now the results:-
mydomain.co.uk ---> transfers to www.mydoamin.co.uk
mydomain.co.uk/ ---> transfer to https://www.mydomain.co.uk

www.mydoamin.co.uk ---> same no change www.mydoamin.co.uk

http://mydomain.co.uk ---> transfers to www.mydomain.co.uk

Now I think I have found out why it playing funny.
If all of these are type in as follows:

http://mydomain.co.uk/
https://mydomain.co.uk/
www.mydomain.co.uk/
mydomain.co.uk/
http://www.mydomain.co.uk/

They all transfer to https://www.mydomain.co.uk.
The problem is a forward slash has to be present for the redirect to work.

Is it possible to leave the .htaccess code the way it is and add more code so when the domains are typed in the address bar with out the forward slash they will also work to.

Hope this is useful sorry for being a pest but I have to resolve this.

Thank you
 

AsheSkyler

New Member
mojo8850 said:
Is it possible to leave the .htaccess code the way it is and add more code so when the domains are typed in the address bar with out the forward slash they will also work too?
I honestly don't know enough to know why the slash is important and I haven't found anything that would say why it's not working.

Oh and to prevent auto-linking there is a checkbox under the post editor (full editor NOT the quick post) that says "Automatically parse links in text", by unchecking that it will leave URLs as plain text.

Thank you! I forgot all about that checkbox. That auto-linking was driving me nuts. I spent a few edits before posting trying to remove the BBC tags before I gave up.
 
Last edited:

chrishirst

Well-Known Member
Staff member
It will be some conflict possibly because of the two duplicated rewrite conditions, .htaccess works by creating an internal request for the new URI, but a missing trailing slash ALSO makes a new request after adding the slash so they are falling over each other.

Try this
Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Which is a "force HTTPS" ruleset and will work with or without a trailing slash.

What that does is check the protocol being used rather than matching characters in the URI.
 

mojo8850

New Member
Wooohoooo Its Working Awesome Friend's Thank You Soooooo Much..

The Code Above Worked With A Little More Of A Revamp. Awesome ;)
 

mojo8850

New Member
Ok.. Now a minor problem.. LOL

My current htaccess file is as follows..

DirectoryIndex index.html index.php

# Use PHP5 Single php.ini as default
AddType x-mapp-php5 .php

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{http_host} ^mydomain.co.uk [nc]
RewriteCond %{http_host} ^www.mydomain.co.uk [nc]
RewriteRule ^(.*)$ https://www.mydomain.co.uk/ [r=301,nc]
RewriteCond %{SERVER_PORT} 443

All The https:// Redirects work perfect.

BUT I have 1 sub domain that also transfers to https://

I don't want to http://forum.mydomain.co.uk to transfer. But I want to leave the others.
 

AsheSkyler

New Member
EWWWWWWWWWWWW pornbot! I never thought I'd miss spambots...

I'll have to remember next time that "gay" means the same thing in both English and Spanish.
 
Top