Thinkphp中去掉index.php

原文地址:http://www.thinkphp.cn/topic/30538.html

例如你的原路径是 http://localhost/test/index.php/index/add
那么现在的地址是 http://localhost/test/index/add
如何去掉index.php呢?

1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置

  1. #LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉

复制代码

2.AllowOverride None 讲None改为 All //在APACHE里面去配置

  1. <Directory "D:/server/apache/cgi-bin">
  2. AllowOverride none 改 AllowOverride ALL
  3. Options None
  4. Order allow,deny
  5. Allow from all
  6. </Directory>

复制代码

3.确保URL_MODEL设置为2,
在项目的配置文件里写

  1. return Array(
  2. ‘URL_MODEL‘ => ‘2‘,
  3. );

复制代码

4 .htaccess文件必须放到跟目录下
这个文件里面加:

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine on
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
  6. </IfModule>

复制代码

补充:在windows下不能建立以点开头的文件,你可以先随便建立一个文件
然后在DOS在操作 rename xxxx.xxxx .htaccess
或者打开记事本写入htaccess然后另存为.htaccess即可
如果出现403错误则将.htaccess打开在开头添加Options +FollowSymlinks
即:

  1. Options +FollowSymlinks
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine on
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
  7. </IfModule>

复制代码

即可解决.
无权限也是加上Options +FollowSymlinks

时间: 2024-08-06 07:56:34

Thinkphp中去掉index.php的相关文章

url中去掉index.php,方便redirect()

01 配置文件 return Array( 'URL_MODEL' => '2',); 02 index.php入口文件下面加入文件 .htaccess -->使用editplus-->另存为 <IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [

ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php

去掉 URL 中的 index.php ThinkPHP 作为 PHP 框架,是单一入口的,那么其原始的 URL 便不是那么友好.但 ThinkPHP 提供了各种机制来定制需要的 URL 格式,配合 Apache .htaccess 文件,更是可以定制出人性化的更利于 SEO 的 URL 地址来. .htaccess文件是 Apache 服务器中的一个配置文件,它负责相关目录下的网页配置.我们可以利用 .htaccess 文件的 Rewrite 规则来隐藏掉 ThinkPHP URL 中的 in

nginx去掉url中的index.php

使用情境:我想输入www.abc.com/a/1后,跳转到www.abc.com/index.php/a/1 配置Nginx.conf在你的虚拟主机下添加:  location / {      if (!-e $request_filename){           rewrite ^/(.*)$ /index.php/$1 last;      } } 如果你的项目入口文件在一个子目录内,则: location /目录/ {      if (!-e $request_filename){

修改apache配置文件去除thinkphp url中的index.php(转)

例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index.php呢? 1.httpd.conf配置文件中加载了mod_rewrite.so模块  //在APACHE里面去配置 复制代码代码如下: #LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉 2.AllowOverride None 讲N

去掉 url 中的 index.php

Apache服务器则开启 mod_rewrite 模块 在 Aoache 配置文件 httpd.conf 中查找  LoadModule rewrite_module modules/mod_rewrite.so  去掉前面 '#' 则为开启 在跟目录创建 .htaccess 文件  内容如下 RewriteEngine On     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     R

修改apache配置文件去除thinkphp url中的index.php

例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index.php呢? 1.httpd.conf配置文件中加载了mod_rewrite.so模块  //在APACHE里面去配置 #LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉 2.AllowOverride None 讲None改为 All 

ThinkPHP 隐藏URL中的 index.php

去掉 URL 中的 index.php 通常的URL里面含有index.php,为了达到更好的SEO效果可能需要去掉URL里面的index.php ,通过URL重写的方式可以达到这种效果,通常需要服务器开启URL_REWRITE模块才能支持. 例如原来的 URL 为: http://127.0.0.1/index.php/Index/insert 去掉 index.php 之后变为: http://127.0.0.1/Index/insert 第一步:更改Apache的httpd.conf 配置

去掉CodeIgniter(CI)默认url中的index.php的步骤(完整版)

去掉CodeIgniter(CI)默认url中的index.php的步骤: 1.打开apache的配置文件,conf/httpd.conf : 1 LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉. 搜索 AllowOverride None(配置文件中有多处),看注释信息,将相关.htaccess的该行信息改为: 1 AllowOverride All 2.在CI的根目录下,即在index.php,system的同级目录下,建立

IIS 8.5 伪静态去掉index.php thinkphp 3.2.2

因为测试都是在win下开发的 win8.1企业版 II8.5 首先安装  Thinkphp 3.2.2 URL Rewrite Module 2.0 http://www.iis.net/downloads/microsoft/url-rewrite#additionalDownloads 上面地址选择 合适的版本下载安装 安装完成后 关闭IIS 在重新打开 在你建立的网站根目录有 web.config 这个文件 输入伪静态规则 <rewrite> <rules> <rule