0

According to this question, Apache should not simply redirect from other ServerAlias domains to the ServerName domain, but in my case, it does.

For example, when I access www.yannbane.net, which is one of my domains point to my server's IP, it redirects me to yannbane.com. When I access www.yannbane.com, it redirects to yannbane.com as well.

This is the behavior that I actually want, but I don't understand what's happening here!

Here's my site's config:

<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>

Here's 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

Here's my .htaccess in my WordPress directory (which is the document root for this virtual host):

# 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

Can anyone tell me why are these redirects happening? And what's the appropriate way of achieving such behavior?

4

1 に答える 1

0

以下のコードを .htaccess に追加して、ドメインを www でリダイレクトできます。

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

実際、これは新しいドメインにリダイレクトするのに役立ちます。ここでは、www.newdomain の代わりに www.yannbane.com を使用できます。

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

于 2013-10-30T19:13:43.613 に答える