2 Replies - 156 Views - Last Post: 25 May 2020 - 11:57 AM Rate Topic: -----

#1 sayhello   User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 365
  • Joined: 12-November 17

use htaccess-file to redirect all requests possible: http to https etc

Posted 25 May 2020 - 08:21 AM

hi there - good day dear artifical soldier, dear no2pencil, hello dear doremilich, and good day dear modi123


This is the .htaccess code for permalinks in WordPress.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>



we have the following ingrediences:

-f and -d part means to give real directories and files higher priority.




how it works:

^index\.php$ - [L] prevents requests for index.php from being rewritten, 



to avoid an unnecessary file system check. If the request is for index.php the directive does nothing

 - and stops processing rules [L].



This following block is all one single rule: this rule says that if it is not a real file and not a real directory, reroute the request to index.php.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]



well - the index.php itself interprets the URL that was requested by the client-machine (since PHP can see the requested URL using $_SERVER['REQUEST_URI']) and it calls the correct code for rendering the page the user requested.


and now to the issue of today: i want to do this for using to redirect HTTP to HTTPs with mydomain - what kind of htaccess do i need to run?

what is wanted: i want to do this for using to redirect HTTP to HTTPs with https://www.example.com and https://example.com/ and http://example.com - what kind of htaccess do i need to run


With my current .htaccess, this is what happens:

https://www.example.com/ - i need this

https://example.com/ -i need this that subsequently redirects to the above which would be great

, it should redirect to the https version:

note: i all way thought that i need to have a new /(and extra vhost to do this)

http://www.example.com/

http://example.com/


Here is the .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>







again: what is wanted: i want to have a redirect that helps in each time & situation With my current .htaccess,

https://www.example.com/ - i need this
https://example.com/ -i need this that subsequently redirects to the above which would be great

what is aimed: all options should load fine, it should redirect to the https version:
note: i allways thought that i need to have a new /(and extra vhost to do this). but perhaps i do not need a second vhost!? Perhaps i can do it with .htaccess too!?

http://www.example.com/
http://example.com/


can you help out here..!?

This post has been edited by Dormilich: 25 May 2020 - 08:47 AM
Reason for edit:: please use the example.com domain for examples, not domains you don't own


Is This A Good Question/Topic? 0
  • +

Replies To: use htaccess-file to redirect all requests possible: http to https etc

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4277
  • View blog
  • Posts: 13,561
  • Joined: 08-June 10

Re: use htaccess-file to redirect all requests possible: http to https etc

Posted 25 May 2020 - 08:48 AM

RewriteCond %{HTTPS} is what you're looking for.
Was This Post Helpful? 0
  • +
  • -

#3 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2751
  • View blog
  • Posts: 8,056
  • Joined: 15-January 14

Re: use htaccess-file to redirect all requests possible: http to https etc

Posted 25 May 2020 - 11:57 AM

There are also loads of examples online for redirecting from HTTP to HTTPS depending on how you want to do it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1