我需要的是将www.my_website123.com
重定向到my_website123.com
,以便将任何网址www.my_website123.com/some_thing
重定向到my_website123.com/some_thing
。我在文件/etc/apache2/sites-available/sub_domain123.main_domain123.com
<VirtualHost *:80>
ServerName my_website123.com
ServerAlias www.my_website123.com
ServerAlias sub_domain123.my_website123.com
ServerAlias files.my_website123.com
ServerAdmin admin@my_website123.com
#DocumentRoot /var/sub_domain123/public
DocumentRoot /web/sub_domain123.my_website123.com/current/public
ErrorLog /var/log/apache2/sub_domain123_errors.log
LogLevel warn
CustomLog /var/log/apache2/sub_domain123_access.log combined
SetEnv RAILS_ENV production
Header set Access-Control-Allow-Origin "http://sub_domain456.my_website123.com"
Header set Access-Control-Allow-Credentials true
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.my_website123\.com$ [NC]
RewriteRule ^(.*)$ http://my_website123.com/$1 [R=301,L]
<Directory /var/sub_domain123/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:443>
.....
哪里
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.my_website123\.com$ [NC]
RewriteRule ^(.*)$ http://my_website123.com/$1 [R=301,L]
是我添加的内容。然后我这样做了:
a2enmod rewrite
/etc/init.d/apache2 restart
它几乎正常工作。但是:
curl -I http://www.my_website123.com
HTTP/1.1 302 Found
Date: Sun, 28 Dec 2014 04:12:04 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.21
Cache-Control: no-cache
ServerAlias www.my_website123.com
?ServerName my_website123.com
重命名为ServerName www.my_website123.com
.com//login
)之外,这是正常的。如何删除它?答案 0 :(得分:0)
您需要在RewriteRule(Reference)中删除尾部斜杠/
。此外,需要ServerName和ServerAlias。因此,更新的规则将如下所示。
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.my_website123\.com$ [NC]
RewriteRule ^(.*)$ http://my_website123.com$1 [R=301,L]
不确定为什么要返回302
。但是,请尝试使用更新后的规则并查看您获得的响应。
祝你好运!