• 0

Help with Domain Name and IP Redirection


Question

Brian Miller

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.

 

 

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0
+BudMan

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

  • Like 1
Link to post
Share on other sites
  • 0
Brian Miller

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

Link to post
Share on other sites
  • 0
+BudMan

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

Link to post
Share on other sites
  • 0
Brian Miller

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.

Link to post
Share on other sites
  • 0
Brian Miller

Does anyone have any idea about this?

Link to post
Share on other sites
  • 0
+BudMan

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..

Link to post
Share on other sites
  • 0
Brian Miller

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.

Link to post
Share on other sites
  • 0
Steven P.

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,

Link to post
Share on other sites
  • 0
+BudMan
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..

  • Like 1
Link to post
Share on other sites
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By flynempire
      I have been successful in one aspect of our redirect but in another it is not working.

      Let me give an explanation of the history of this. We had almost two years ago hired a company to create a mobile site for us using Magento. Well Magento was not easy to work with and basically this whole venture was a disaster!

      I took more than a year for this company to finish this site and that is with me doing a lot of the work even though I never worked in Magento before. I basically entered all the products based on info I found online because they were no help at all.

      A group of developers and they could not do anything right!  Anyways when it was finished it never worked properly and the host they found for us with has been the only good thing they did. Inside the host server space for us they installed magento in a folder called m which they made as root. I dont know why they did not do it outside of this folder but I just kept with it.

      Not longer after the owners told me to find another system which I did called AbanteCart. In a month I had the system up and running much quicker than those developers. I installed this in a sub-folder of m called store. This has worked for a year but now they wanted Amazon payments so I used WooCommerce/Wordpress and that is now up and running well under a different sub-folder of m called Shop.

      I have the following code in our .htaccess file and it works.
      Options +FollowSymLinks
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^(m.)?
      kleinerts.com$
      RewriteRule ^(/)?$ Shop [L]
       
      This redirects from m.kleinerts.com to m.kleinerts.com/Shop which is what we need and no problem.

      The issue is we are still getting orders at the Abante Mobile Site which we want to stop.

      Is there another redirect code I can use to redirect m.kleinerts.com/store to m.kleinerts.com/Shop ?

      I need to keep up the Abante site for awhile longer at least the Admin so they can finish up the orders that are pending and look back on previous orders from Consumers. After some time I will take it down completely.

      Thanks

       
    • By robertobaggio2k
      Hey guys and gals,
      I've changed my domain name and wanted to update the .htaccess file.
      Would the following code be correct?
      # BEGIN WordPress
      <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_HOST} !^uvdesigns.ca/$ [NC]
      RewriteRule ^(.*)$ http://webdesigner-toronto.ca/$1 [R]
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>
      # END WordPress