Home > php教程 > php手册 > 配置.htaccess单点入口

配置.htaccess单点入口

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:49:23
Original
989 people have browsed it

首先启用mod_rewrite 模块(按操作系统不同来调整,当前linux)
1,Apache启用Mod_rewrite模块

编辑:/etc/apache2/httpd.conf
取消注释:LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

2,选择Directory 把AllowOverride None 改成 AllowOverride All 就可以了。

3,重启Apache
 
项目根目录创建文件.htaccess 将请求转向 public 目录 (按需求调整)
1
2     RewriteEngine on
3     RewriteRule    ^$    public/    [L]
4     RewriteRule    (.*) public/$1    [L]

 
最后将请求转向 public/index.php 文件,(在这里分发所有的请求)
 
1
2 RewriteEngine On
3
4 RewriteCond %{REQUEST_FILENAME} !-f
5 RewriteCond %{REQUEST_FILENAME} !-d
6
7 RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
8
9

 
app->public->index.php
这样可以实现一个网站的单入口,也是MVC模式的起点,下一步可以来尝试分发我们的url 为 三部分 controller/action/querystring.....

 


摘自 warcraft

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template