Secure URL with mod_rewrite and symfony

I have several pages that need to be protected through mod_rewrite, and the code is based on the mvc architecture

Let me say that I have a login page, its URL is http://www.example.com/login , it needs to be redirected to https://www.example.com/login

If any url other than the desired secure URL uses https, we need to change it to http for example https://www.example.com/sitemap must be redirected to http://www.example.com/sitemap

I am using the following code in .htaccess

  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^login$ https://%{HTTP_HOST}/login [R=301,L]

  RewriteCond %{SERVER_PORT} ^443$
  RewriteCond %{REQUEST_URI} !^/login$
  RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

  # we check if the .html version is here (caching)
  RewriteRule ^$ index.html [QSA]
  RewriteRule ^([^.]+)$ $1.html [QSA]
  RewriteCond %{REQUEST_FILENAME} !-f

  # no, so we redirect to our front web controller
  RewriteRule ^(.*)$ index.php [QSA,L]

The problem I am getting is looping where it says: "The server redirects the request to this address in a way that will never be completed."

, URL- , . .htaccess, symfony.

https://www.example.com/login

https://www.example.com/account

https://www.example.com/register

0
2

  # SSL here
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^/?(login|account|register|mypage)(.*) https://%{HTTP_HOST}/$1$2 [R,L]

  # not anywhere else
  RewriteCond %{SERVER_PORT} !^80$
  RewriteCond %{REQUEST_URI} !^/?(login|account|register|mypage)(.*)
  RewriteCond %{REQUEST_URI} !^/?index\.php$
  RewriteRule .? http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

, , .

0

, .

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^login$ https://%{HTTP_HOST}/login [R=301,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^login$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
0

All Articles