阿帕奇VirtualDocumentRoot重定向不存在的域 [英] Apache VirtualDocumentRoot redirect non-existing domains

查看:318
本文介绍了阿帕奇VirtualDocumentRoot重定向不存在的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用VirtualDocumentRoot有多个域和子域我'。 一切顺利的话,直到有人试图通过IP或不存在的域到达我的服务器。例如10.10.10.10至极的结果到一个404 Not Found错误。 也许有人在那里可以帮助我找到一个解决方案,以重定向不存在的域名或IP到我的主域名www.example.com?

我要明确指出:不存在的子域被重定向,但不存在的域不是

HTTPD.CONF:

 <虚拟主机*:80>
        服务器名称默认
        ServerAlias​​ *
        #www.example.com == /httpdocs/example.com/www/
        VirtualDocumentRoot /httpdocs/%-2.0.%-1/%-3
    < /虚拟主机>
 

/httpdocs/example.com/.htacces:

 #重写所有不存在的子域到www。
的RewriteCond%{HTTP_HOST}例如\ .COM $
。重写规则^ * $ HTTP://www.example.com% {REQUEST_URI} [R = 301,L]
 

解决方案

解决我的问题是:
为此添加到.htacces在我的根目录文件夹/httpdocs/.htaccess

这将导致所有的非现有域结束运算在它们拾起htaccess的根文件夹。 (无符号链接了)

 #开启重写引擎
RewriteEngine叙述上

#重写所有不存在的域example.com
的RewriteCond%{HTTP_HOST}!例如\ .COM $ [NC] #just此处添加您的主域名
。重写规则^ * $ HTTP://www.example.com% {REQUEST_URI} [R = 301,L]
 

I'am using VirtualDocumentRoot to have multiple domains and subdomains. Everything goes well until someone tries to reach my server by IP or an non-existing domain. For example 10.10.10.10 wich results into an 404 Not Found error. Maybe someone out there can help me find an solution to redirect non-existing domains or IP to my main domain www.example.com?

Let me be clear: non-existing subdomains are being redirected but non-existing domains are not.

HTTPD.CONF:

<VirtualHost *:80>
        ServerName default
        ServerAlias *
        #www.example.com == /httpdocs/example.com/www/
        VirtualDocumentRoot /httpdocs/%-2.0.%-1/%-3
    </VirtualHost>

/httpdocs/example.com/.htacces:

# Rewrite all non-existing subdomains to www.
RewriteCond %{HTTP_HOST} example\.com$
RewriteRule ^.*$ http://www.example.com%{REQUEST_URI} [R=301,L]

解决方案

The Solution to my problem was:
To add this to .htacces in my webroot folder /httpdocs/.htaccess

This will cause all non-existing domains to end op in root folder where they are picked up by the .htaccess. (no symbolic links anymore)

# Enable Rewrite Engine
RewriteEngine on

# Rewrite all non-existing domains to example.com
RewriteCond %{HTTP_HOST} !example\.com$ [NC] #just add your main domain here
RewriteRule ^.*$ http://www.example.com%{REQUEST_URI} [R=301,L]

这篇关于阿帕奇VirtualDocumentRoot重定向不存在的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆