S
S
Sergey2017-02-01 06:39:30
PHP
Sergey, 2017-02-01 06:39:30

How to make a rule for Apache to redirect from http to https except for a URL of a certain mask?

How to make a rule for Apache to redirect from http to https except for a URL of a certain mask?
It just so happened that api must work over http and https, and everything else only over https.
What is now:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !/api
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_URI} \.(css|jpg|gif|png|zip|rar|doc|xls|js|tif|tiff|docx|xlsx|ico)$
RewriteRule ^(.*)$ $1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pag=$1 [L,QSA]

From http to https it redirects correctly, but from sitename.ru/api/action we will be redirected to https://sitename.ru/index.php?pag=/api/action
How to solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question