强制www.在铁轨

Chr*_*ris 3 ruby-on-rails

我通常习惯使用.htaccess文件来强制域使用www.(即http://www.example.com而不是http://example.com):

#Options +Indexes
RewriteEngine on
RewriteBase /

Redirect permanent "www.example.com" "http://www.example.com"
Redirect permanent "example.com" "http://www.example.com"
Run Code Online (Sandbox Code Playgroud)

但是这在rails应用程序中不起作用.除此之外的轨道是什么?

khe*_*lll 6

检查一下

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(example\.com)(:80)? [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
order deny,allow
Run Code Online (Sandbox Code Playgroud)

摘自http://www.htaccesseditor.com/en.shtml#a_WWW

注意: .htaccess文件应放在Rails项目的公用文件夹中.