Remove www site-wide, force https on certain directories and http on the rest?

前端 未结 4 1333
野的像风
野的像风 2020-12-08 05:50

Firstly, I would like to remove the www. from my domain name

http://www.example.com => http://example.com

I would also like for certain directories to be sec

相关标签:
4条回答
  • 2020-12-08 06:10

    This code works for me:

    <IfModule mod_rewrite.c>
    
       RewriteEngine on
    
       RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
       RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
       RewriteCond %{HTTPS} !=on
       RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    
    </IfModule>
    
    0 讨论(0)
  • 2020-12-08 06:12

    After reading this all post time line i have get success for following error: My website(c4dprime.com) was attached https: in mozilla firefox browser. Google and internet explore are show domain address as http: (The real problem in firefox) I did not want https: for my domain in any browser because one unknow redirect attached with my domain by https: (Cause for this error)after Installing following plugins in wordpress,(Easy redirect for ssl).... I have told to every one do not use any low level plugins for wordpress.

    Anyway! After reading many articles and tutorials at this topic via google search engine. Now i am happy to say i have solve this problem from this post tips. Remember one thing about me i am new to in this form and wordpress.

    This tip is help full for me

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
    RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
    

    After edit or some changes in my .htaccess file following code i have use now with solved this error.

    AddHandler c4d-prime .com
    
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteBase /
    RewriteRule ^$ http://www.c4dprime.com/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    0 讨论(0)
  • 2020-12-08 06:21

    remove www (tested):

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTP_HOST} ^www\.yoursite\.com$ [NC]
    RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]
    

    redirect (not tested):

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{THE_REQUEST} \/login/?.*\ HTTP [NC]
    RewriteRule ^(.*)$ https://yoursite.com/login [L,R=301]
    
    0 讨论(0)
  • 2020-12-08 06:25

    Try these rules:

    # remove www from host
    RewriteCond %{HTTP_HOST} ^www\.(.+)
    RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
    RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]
    
    # force HTTPS
    RewriteCond %{HTTPS} =off
    RewriteRule ^(login|foo|bar|…)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # force HTTP
    RewriteCond %{HTTPS} =on
    RewriteRule !^(login|foo|bar|…)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    You also might want to add some additional conditions to only change the protocol on GET and HEAD requests but not on POST requests.

    0 讨论(0)
提交回复
热议问题