htaccess redirect 4 specific pages to https

前端 未结 2 893
礼貌的吻别
礼貌的吻别 2021-01-05 09:35

I have a problem where I need to redirect 4 specific pages on my website to their https secure versions.

I currently have an htaccess file which is redirecting both

相关标签:
2条回答
  • 2021-01-05 09:58
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    
    #redirect www.mydomain.com to mydomain.com (or any other subdomain)
    RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
    RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
    
    #force https for certain pages    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(page1\.php|page2\.php|page3\.php|page4\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
    
    0 讨论(0)
  • 2021-01-05 10:11

    I have modified and cleaned up your code. You can use this code in your .htaccess file in $DOCUMENT_ROOT:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    # HTTPS is not already on
    RewriteCond %{HTTPS} !=on
    # Redirect to HTTPS is URI is page1.php OR page2.php OR page3.php OR page4.php
    RewriteRule ^page[1234]\.php$ https://mydomain.com%{REQUEST_URI} [L,R]
    
    0 讨论(0)
提交回复
热议问题