You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Wilmer Arambula <te...@gmail.com> on 2018/03/03 23:34:33 UTC

[users@httpd] Reditect HTTP to HTTPS .htaccess

i have the following .htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On

    ####
    # Certain hosts may require the following line.
    # If vanilla is in a subfolder then you need to specify it after the /.
    # (ex. You put Vanilla in /forum so change the next line to:
RewriteBase /forum)
    ####
    #RewriteBase /

    # Make sure that / doesn't try to go to index.php without a rewrite :)
    DirectoryIndex disabled

    ####
    # Deny access to certain directories that SHOULD NOT be exposed.
    ####
    RewriteRule (^|/)\.git - [L,R=403]
    RewriteRule ^cache/ - [L,R=403]
    RewriteRule ^cgi-bin/ - [L,R=403]
    RewriteRule ^uploads/import/ - [L,R=403]
    RewriteRule ^vendor/ - [L,R=403]

    ####
    # Prevent access to any php script by redirecting the request to /index.php
    # You can add an exception by adding another RewriteCond after this one.
    # Example: RewriteCond %{REQUEST_URI} !^/yourscriptname.php$
    # You can comment out this section if it causes you problems.
    # This is just a nice to have for security purposes.
    ####
    RewriteCond %{REQUEST_URI} !/index.php$
    RewriteRule (.+\.php) [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]

    ####
    # Redirect any non existing file/directory to /index.php
    ####
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) index.php [E=X_REWRITE:1,E=X_PATH_INFO:/$1,L]

    ####
    # Add the proper X_REWRITE server variable for rewritten requests.
    ####
    RewriteCond %{ENV:REDIRECT_X_REWRITE} .+
    RewriteCond %{ENV:REDIRECT_X_PATH_INFO} (.+)
    RewriteRule ^index\.php -
[E=X_REWRITE:1,E=!REDIRECT_X_REWRITE,E=X_PATH_INFO:%1,E=!REDIRECT_X_PATH_INFO,L]
</IfModule>

What would be the best way to redirect http to https, I have searched in
google and tried several configurations but so far I have not been able to
make it work correctly ?

Re: [users@httpd] Re: Reditect HTTP to HTTPS .htaccess

Posted by D'Arcy Cain <da...@vex.net>.
On 03/04/2018 08:07 AM, LuKreme wrote:
> I don't do this in .htaccess, I do it in <virtualHost>
> 
> <VirtualHost *:80>
>    ServerName www.example.com
>    ServerAlias example.com
>    Redirect / https://www.example.com/
>  </Virtualhost>
> 
> But something like this should work in .htaccess as well:
> 
> RewriteEngine On 
>  RewriteCond %{SERVER_PORT} 80 
>  RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
> 
> I think, perhaps based on nothing at all, that doing it in VirtualHosts works better.

Well, at the very least you only have to parse it once at startup.  If
you don't have a .htaccess file at all you also save an extra file open
on every hit.

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:darcy@Vex.Net
VoIP: sip:darcy@Vex.Net

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Reditect HTTP to HTTPS .htaccess

Posted by LuKreme <kr...@kreme.com>.
I don't do this in .htaccess, I do it in <virtualHost>

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

But something like this should work in .htaccess as well:

RewriteEngine On 
 RewriteCond %{SERVER_PORT} 80 
 RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

I think, perhaps based on nothing at all, that doing it in VirtualHosts works better.

-- 
My main job is trying to come up with new and innovative and effective ways to reject even more mail. I'm up to about 97% now.

> On Mar 3, 2018, at 15:34, Wilmer Arambula <te...@gmail.com> wrote:
> 
> What would be the best way to redirect http to https, I have searched in google and tried several configurations but so far I have not been able to make it work correctly ?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org