Help with Domain Name and IP Redirection

Recommended Posts

Brian Miller    1,559

Can someone help me with redirecting a domain name to the HTTPS version of itself?  I've seen many examples online but none of them seems to fit my specific requirements.

 

I think I need multiple "if" conditions that will redirect any non-"https://www" queries to the "https://www" version of itself.

 

Below is the 301 redirection options I need to include in the .htaccess file:

 

 Routing-Table.thumb.png.d04f63ab7358df43c6012f2427c04c10.png

 

From the above table, you'll notice that I need at least 3 condition checks within my single .htaccess file. Also, as I'm using the same .htaccess file in my localhost as well as on my public web site, the "if" conditions will also need to accommodate localhost as well.

 

I can only test for either A, B or C from the list above.  I can't test a combination of all of them.

 

Please can a kind Neowin expert assist me?

 

Thank you.

 

 

Share this post


Link to post
Share on other sites
+BudMan    3,018

Why would the standard redirect all to https not work?

 


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

Why would you be using local host and not just use fqdn www.test.com that resolve to your local IP your site is listening on?  Be simple host file on your local machine for that matter.

 

You should be able to replace the variables with the exact fqdn you want to use https://www.test.com

Share this post


Link to post
Share on other sites
Brian Miller    1,559

Will that code for for all conditions as defined in the routing table?

Share this post


Link to post
Share on other sites
+BudMan    3,018

What?  Makes Zero sense.. Did you post your answer to some other thread?  What you ask has zero to do with any routing table.

Share this post


Link to post
Share on other sites
Brian Miller    1,559

There is a actual "table", in my post (click here to see it), it illustrates the place the user start at and where I want them to end at (a "route").

 

So if a user tries "test.com",  they end up at "https://www.test.com",

If a user tries "www.test.com",  they end up at "https://www.test.com",

If a user tries "https://test.com",  they end up at "https://www.test.com",

If a user tries "255.255.255.255",  they end up at "https://www.test.com",

And also,

If a user tries "localhost",  they end up at "https://localhost".

If a user tries "brianpc",  they end up at "https://brianpc".

If a user tries "192.186.0.100",  they end up at "https://brianpc".

 

Original question was too confusing.  I hope you can help.

Thank you.

Share this post


Link to post
Share on other sites
Brian Miller    1,559

Does anyone have any idea about this?

Share this post


Link to post
Share on other sites
+BudMan    3,018

Already answered dude.. I gave you the code to redirect anything http to https which can be edited to go exactly where you want vs what they send..

Share this post


Link to post
Share on other sites
Brian Miller    1,559

Thanks Bud but you didn't exact answer the question. Redirecting https to https is easy but my questions was not to redirect http > https; it was to redirect multiple states of the URL to https://www.  So the actual question remains unanswered.  If it helps you, read this message, and see if you actually answered my question or not.

Share this post


Link to post
Share on other sites
Steven P.    9,298

See the section Redirection with mod_rewrite here: https://www.somacon.com/p145.php the second example where it talks about "all non-www traffic to the www prefixed host" maybe that helps you,

Share this post


Link to post
Share on other sites
+BudMan    3,018
45 minutes ago, Brian Miller said:

it was to redirect multiple states of the URL to https://www.

Dude yes the information redirects whatever they send to that via https, you can just edit it to go www.something.com

 

This is not all that difficult...  Here.. Lets go through it line by line

 

A,B and C - YES

D - Again yes..

EFG - Yes once again... But Freaking why??  Are you too freaking lazy to just go to https://www.domain.tld

 

And have that resolve to whatever your localhost box IP is? via simple entry in your host file on your host or via your dns you run on your network.  But to be honest your running Apache you should just do it via a redirect in your conf

 

http://httpd.apache.org/docs/current/rewrite/avoid.html#redirect

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost>

 

Also if you want your using to use https you should really be setting up HSTS..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.