安全URL与mod_rewrite的和symfony中 [英] Secure Url with mod_rewrite and symfony
问题描述
我有需要基于MVC架构通过mod_rewrite的和code固定的几页
I have few pages which need to be secured through mod_rewrite and the code is based on mvc architecture
让我说,我有一个页面登录其网址是 http://www.example.com/login一>,它需要被重定向到 https://www.example.com/login
Let me say I have a page login its url is http://www.example.com/login it needs to be redirected to https://www.example.com/login
如果任何URL超过所需保护的URL其他用途,我们需要改变它到http例如HTTPS https://www.example.com/sitemap 必须重定向到的 http://www.example.com/sitemap
If any url other than desired secured 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
我使用下面的code在.htaccess
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 get is, it gets looped where it says "server is redirecting the request for this address in a way that will never complete".
您可以请帮我带,其中只有以下网址担保和其他人都没有解决。我需要的.htaccess而不是与任何symfony的插件的解决方案。
Can you please help me out with the solution where only the following urls are secured and others are not. I need a solution with .htaccess and not with any symfony plugin.
https://www.example.com/account
https://www.example.com/register
感谢
尼扎姆
推荐答案
这工作完美的我。
# 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]
感谢$ P $点,阿马尔,哈利的解决方案。
Thanks Prem, Amar, Harry for the solution.
这篇关于安全URL与mod_rewrite的和symfony中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!