Apache服务器的URL重定向

前端时间要整个Apache重定向功能,在此记录一下。

一、安装Apache

Windows版本官方下载安装文件httpd-2.2.21-win32-x86-openssl-0.9.8r,选择安装目录,直接安装就好。

安装完后,Services 和 任务栏会有Apache的服务出现。

二、Apache目录结构

主要是conf配置信息文件夹和modules功能模块文件夹。

主要的配置文件:

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf,

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf。

三、开启虚拟主机配置

修改以下配置,可以在httpd-vhosts.conf中添加不同的主机

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

<VirtualHost *:8080>
    ServerAdmin webmaster@dummy-host.englishnet
    DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
    ServerName dummy-host.englishnet
    ServerAlias www.dummy-host.englishnet
    ErrorLog "logs/dummy-host.englishnet-error.log"
    CustomLog "logs/dummy-host.englishnet-access.log" common
    
    RewriteEngine ON
    RewriteRule /index3.html http://passport.cnblogs.com/user/signin [R]
</VirtualHost>

<VirtualHost *:8090>
    ServerAdmin webmaster@dummy-host2.englishnet
    DocumentRoot "E:/ASoft/Apache/ApacheTest"    
    AspNetMount / "E:/ASoft/Apache/ApacheTest"
    
    ServerName dummy-host2.englishnet
    ErrorLog "logs/dummy-host2.englishnet-error.log"
    CustomLog "logs/dummy-host2.englishnet-access.log" common
            
    <Directory "E:/ASoft/Apache/ApacheTest">
        Options FollowSymlinks ExecCGI
        Options Indexes FollowSymLinks Includes ExecCGI 
        AllowOverride All
        Order allow,deny
        Allow from all
        DirectoryIndex Default.aspx index.html
    </Directory>
        
    RewriteEngine ON
    RewriteRule ^/postdata.ashx$ http://testbx.palmyou.com/v7s-insurance-wap/individualend/meiyawxpay [R,P]
    #/RevertData.ashx
</VirtualHost>
View Code

 

四、Apache对Asp.net的支持

2.2以下版本需要安装.net功能模块mod_aspdotnet-2.2.0.2006-setup-r2,这个模块支持.net 4以下的版本。

需要在httpd.conf添加以下的aspdotnet_module的配置:

#asp.net
LoadModule aspdotnet_module "modules/mod_aspdotnet.so"
AddHandler asp.net asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo
<IfModule mod_aspdotnet.cpp>
# Mount the ASP.NET example application
#AspNetMount /active "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
# Map all requests for /active to the application files
#Alias /active "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
# Allow asp.net scripts to be executed in the active example
#<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
#Options FollowSymlinks ExecCGI
#Order allow,deny
#Allow from all
#DirectoryIndex Default.htm Default.aspx
#</Directory>
# For all virtual ASP.NET webs, we need the aspnet_client files
# to serve the client-side helper scripts.
AliasMatch /aspnet_client/system_web/(\d+)_(\d+)_(\d+)_(\d+)/(.*) "C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4"
<Directory "C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles">
Options FollowSymlinks
Order allow,deny
Allow from all
</Directory>
</IfModule>
View Code


五、重定向功能

开启代理Module:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

POST重定向P、URL重定向R:

RewriteEngine ON
RewriteRule ^/postdata.ashx$ http://www.aaaa.com/v7s-wap/individualend/ddddd [R,P]

反向代理:

#反向代理设置
ProxyPass /proxy http://www.proxypass.com/proxy
ProxyPassReverse /proxy http://www.proxypass.com/proxy

 

posted on 2016-07-18 00:10  欣静赏悦  阅读(762)  评论(0编辑  收藏  举报