使用.htaccess在网站中重定向

时间:2015-03-19 14:32:40

标签: .htaccess web redirect

任何人都可以帮助我将所有http://example.comhttp://www.example.com重定向到https://www.example.com。我最近为我的网站购买了一个ssl,因此需要将其重定向。使用.htaccess重定向对我来说会更有用。提前谢谢。

1 个答案:

答案 0 :(得分:0)

那里有很多解决方案。这是一个指向apache wiki的链接,它直接处理这个问题。

http://wiki.apache.org/httpd/RewriteHTTPToHTTPS

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*)$ https://www.example.com/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context