apache 配置虚拟目录+默认页+隐藏index.php

配置虚拟目录+默认页

如果有多个项目文件夹,怎么配置让localhost指向其中的某个文件夹呢。

1.检查apache的配置文件httpd.conf,看Virtual hosts模块是否开启。

Include conf/extra/httpd-vhosts.conf 。前面的【#】需要去除。

2.打开httpd-vhosts文件, 这里由于80端口被占用了,所以用了8080

<VirtualHost *:8080>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:\wamp\www\
myproject\"
    ServerName localhost
    ServerAlias localhost
    <IfModule dir_module>
        DirectoryIndex
  index.php
     </IfModule>

    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

DocumentRoot:项目路径,上例为wamp里面的路径,apache中可以为/www/myproject/Web

ServerName:改为localhost,此配置也可以不需要的

DirectoryIndex:当输入localhost时,默认访问的页面

隐藏index.php

如果需要将127.0.0.1/index.php 改为通过127.0.0.1/index。来访问该怎么实现呢?

这里需要使用apache的Rewrite功能。

1.检查apache的配置文件httpd.conf,看rewrite_module模块是否开启。

LoadModule rewrite_module modules/mod_rewrite.so。前面的【#】需要去除。

2.设置httpd-vhosts文件内容

<VirtualHost *:80>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !^/(css|js|images|ajax)/.*$
        RewriteRule ^(.+)$ /
index.php/$1
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "C:\wamp\www\
myproject"
        ServerName localhost
        ServerAlias localhost
        <IfModule dir_module>
            DirectoryIndex
index.php
          </IfModule>
        ErrorLog "logs/dummy-host.example.com-error.log"
        CustomLog "logs/dummy-host.example.com-access.log" common
        </VirtualHost>

RewriteEngin:设置为【on】,表示路由开启

RewriteCond:路由条件,这里设置如果是访问(css,js,images,ajax)文件夹,则不需要路由

RewriteRule:除了路由条件里面排除的,访问其它的地址,都将跳转到index.php里操作

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值