同一域内的Apache URL重定向

时间:2016-07-13 09:13:24

标签: apache mod-rewrite

我有一个网址为abc.com。现在我想要的是,只要在浏览器中点击该URL,它就应该重定向到www.abc.com/index.jsp。如何使用apache完成此操作?

这就是我所做的:

  

VirtualHost *:80>

ProxyRequests off
ProxyPreserveHost On
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/
ProxyPassReverse /  http://localhost:8080/

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel error

<Location />
            Options +ExecCGI
            AddHandler cgi-script .cgi
            AuthType basic
            AuthName "private area"
            AuthUserFile  "/etc/httpd/conf/.htpasswd"
            Require valid-user    </Location> </VirtualHost>

1 个答案:

答案 0 :(得分:0)

将此添加到页面根目录中的.htaccess中

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

编辑:

也可以在vhost文件的末尾使用它:

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>