Apache重定向表单服务器别名,即使它显然不应该

时间:2013-10-28 10:25:26

标签: linux wordpress apache redirect dns

根据this question,Apache 不应该只是从其他ServerAlias域重定向到ServerName域,但在我的情况下,确实如此。

例如,当我访问www.yannbane.net时,我的域名之一指向我服务器的IP,它会将我重定向到yannbane.com。当我访问www.yannbane.com时,它也会重定向到yannbane.com。

这是我真正想要的行为,但我不明白这里发生了什么!

这是我的网站配置:

<VirtualHost *:80>
    ServerName yannbane.com
    ServerAlias yannbane.net yannbane.org www.yannbane.net www.yannbane.org www.yannbane.com
    DocumentRoot "/var/www/yannbane.com/wordpress"
    ErrorLog "/var/log/yannbane.com/wordpress/error.log"
</VirtualHost>

这是apache2.conf:

ServerName localhost

Mutex file:${APACHE_LOCK_DIR} default    
PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

这是我的WordPress目录中的.htaccess(这个虚拟主机的文档根目录):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

有谁能告诉我为什么会发生这些重定向?什么是实现这种行为的适当方式?

1 个答案:

答案 0 :(得分:0)

您可以在.htaccess中添加以下代码,以使用www

重定向域
 Options +FollowSymLinks
 RewriteEngine on
 RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

实际上这有助于重定向新域名,在这里我们可以使用www.yannbane.com而不是www.newdomain,

http://techietent.blogspot.in/2013/03/url-redirection-using-htaccess.html