2017-01-17 3 views
1

Я погрузка каждую страницы более https используя правило следующим образом в .htaccessИсключить некоторые каталоги, а перенаправление на HTTPS

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

Мне нужно перенаправить каждую страницу на вебе-сайте, чтобы загрузить более https протокола, за исключением некоторых каталогов. Я попытался с помощью этого правила

RewriteRule ^dont-load-under-https-folder/ - [L,NC]

Но, по-прежнему применяется к этому dont-load-under-https-folder

Вот весь мой код Htaccess

IndexIgnore * 

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

RewriteCond %{HTTP_HOST} ^52\.76\.80\.144$ 
RewriteRule ^(.*)$ https://mywebsite.com/$1 [L,R=301] 

RewriteRule ^http://52.76.80.144//(.*)$ /$1 [R=301,NC,L] 

## don't touch /forum URIs 
RewriteRule ^forums/ - [L,NC] 
RewriteRule ^detector/ - [L,NC] 

RewriteRule ^admin/ - [L,NC] 
RewriteRule ^b2b/ - [L,NC] 
RewriteRule ^blog/ - [L,NC] 
RewriteRule ^config/ - [L,NC] 
RewriteRule ^hub/ - [L,NC] 

# To remove www header 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule^http://%1%{REQUEST_URI} [L,R=301,NE] 

RewriteCond %{THE_REQUEST} /(\w+)\.php\?param=([^\s&]+) [NC] 
RewriteRule^%1/%2? [R=301,L,NE] 


## hide .php extension snippet 

# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R=301,NE,L] 

# handle ?param=... 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f 
RewriteRule ^(.+)/([\w-]+)/?$ $1.php?param=$2 [L,QSA] 



# To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*?)/?$ $1.php [L] 
RewriteRule ^ending/thankyou(.*?)/?$ $1.php [L] 

RewriteCond %{THE_REQUEST} /main\.html[\s?] [NC] 
RewriteRule ^main\.html$/[L,R=301,NC] 

RewriteRule ^/?$ main.html [L] 


# compress text, html, javascript, css, xml: 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/x-javascript 

# Or, compress certain file types by extension: 
<files *.html> 
SetOutputFilter DEFLATE 
</files> 

AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/x-javascript 

AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
AddOutputFilterByType DEFLATE font/ttf 
AddOutputFilterByType DEFLATE font/otf 
AddOutputFilterByType DEFLATE image/svg+xml 
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
<IfModule mod_deflate.c> 
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript 
</IfModule> 


<IfModule mod_headers.c> 
    # WEEK 
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> 
     Header set Cache-Control "max-age=604800, public" 
    </FilesMatch> 

    # WEEK 
    <FilesMatch "\.(js|css|swf)$"> 
     Header set Cache-Control "max-age=604800" 
    </FilesMatch> 
</IfModule> 

<IfModule mod_deflate.c> 
    SetOutputFilter DEFLATE 
    SetEnvIfNoCase Request_URI \ 
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary 
</IfModule> 

<IfModule mod_expires.c> 
AddType font/ttf .ttf 
AddType font/otf .otf 
AddType font/x-woff .woff 
AddType image/svg+xml .svg 
AddType application/vnd.ms-fontobject .eot 

    ExpiresActive on 
    ExpiresByType image/jpg "access 2 month" 
    ExpiresByType image/gif "access 2 month" 
    ExpiresByType image/jpeg "access 2 month" 
    ExpiresByType image/png "access 2 month" 
    ExpiresByType text/css "access 2 month" 
    ExpiresByType application/x-javascript "access plus 2 month" 
    ExpiresByType text/javascript "access plus 2 month" 
    ExpiresByType application/javascript "access plus 2 month" 
    ExpiresByType image/x-icon "access plus 12 month" 
    ExpiresByType image/icon "access plus 12 month" 
    ExpiresByType application/x-ico "access plus 12 month" 
    ExpiresByType application/ico "access plus 12 month" 

ExpiresByType font/ttf "access plus 12 month" 
ExpiresByType font/otf "access plus 12 month" 
ExpiresByType application/vnd.ms-fontobject "access plus 12 month" 
ExpiresByType font/x-woff "access plus 12 month" 
ExpiresByType image/svg+xml "access plus 12 month" 
</IfModule> 
+1

с вашего вопроса Его непонятно, что/где именно проблема. отправьте свой полный htaccess – starkeen

+0

@starkeen Проверьте мой код htaccess –

+0

Ваши правила не в правильном порядке. Установите правила #Dont touch dirs перед правилами перенаправления https. – starkeen

ответ

1

Это заставляет все к HTTPs за исключением каталоги, указанные в скобках:

RewriteEngine On 

#Force everything to HTTPs 
RewriteCond %{HTTP:X-Forwarded-SSL} !on 
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301] 

#Checks if HTTPs is on for foobar & foobar2, if it is, turn it off 
RewriteCond %{HTTP:X-Forwarded-SSL} =on 
RewriteCond %{REQUEST_URI} !^\/(foobar|foobar2) 
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301] 

Вы можете добавить столько каталогов, сколько захотите, а просто разделите их на |. Замените foobar & foobar2 и т. Д. С каталогами, которые вы хотите исключить.

Смежные вопросы