thinkPHP Apache 优化url,隐藏index.php所需配置
2016-09-12 11:39
676 查看
例如原先路径为:http://localhost/ehome/index.php/Index/index
现在想把index.php去掉,优化缩短url的长度,变为http://localhost/ehome/Index/index
下面介绍在thinkPHP框架中,Apache服务器对这种url优化的配置:
1:首先,找到你的Apache服务器的httpd.conf文件,在该文件中配置加载mod_rewrite.so模块,具体操作是在此文件中找到 #LoadModule
rewrite_module modules/mod_rewrite.so,去掉前面的#即可,代码如下:
LoadModule rewrite_module modules/mod_rewrite.so
2:在httpd.conf文件中,修改Apache所指向的网站目录下的AllowOverride 的值,llowOverride
none 改 AllowOverride ALL以我的为例:
<Directory "D:/wamp/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride all<span style="color:#ffffff;">
</span>
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Order Deny,Allow
Allow from all
Allow from all
</Directory>3:配置为httpd.conf文件后,接下来就是配置项目的config.php文件了,把URL_MODEL的值改为2
'URL_MODEL' => 2, // URL模式——REWRITE模式4:最后一步就是在网站的根目录下(与项目入口文件index.php同级)添加一个.htaccess文件,写相关配置,内容如下:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
完成以上四步就大功告成了!
注:发现在第三步中,将URL_MODEL=>1的时候也是可以的,我用的是thinkphp3.1
现在想把index.php去掉,优化缩短url的长度,变为http://localhost/ehome/Index/index
下面介绍在thinkPHP框架中,Apache服务器对这种url优化的配置:
1:首先,找到你的Apache服务器的httpd.conf文件,在该文件中配置加载mod_rewrite.so模块,具体操作是在此文件中找到 #LoadModule
rewrite_module modules/mod_rewrite.so,去掉前面的#即可,代码如下:
LoadModule rewrite_module modules/mod_rewrite.so
2:在httpd.conf文件中,修改Apache所指向的网站目录下的AllowOverride 的值,llowOverride
none 改 AllowOverride ALL以我的为例:
<Directory "D:/wamp/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride all<span style="color:#ffffff;">
</span>
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Order Deny,Allow
Allow from all
Allow from all
</Directory>3:配置为httpd.conf文件后,接下来就是配置项目的config.php文件了,把URL_MODEL的值改为2
'URL_MODEL' => 2, // URL模式——REWRITE模式4:最后一步就是在网站的根目录下(与项目入口文件index.php同级)添加一个.htaccess文件,写相关配置,内容如下:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
完成以上四步就大功告成了!
注:发现在第三步中,将URL_MODEL=>1的时候也是可以的,我用的是thinkphp3.1
相关文章推荐
- 修改apache配置文件去除thinkphp url中的index.php
- 修改apache配置文件去除thinkphp url中的index.php
- 修改apache配置文件去除thinkphp url中的index.php(转)
- 修改apache配置文件去除thinkphp url中的index.php
- 修改apache配置文件去除thinkphp url中的index.php
- 修改apache配置文件去除thinkphp url中的index.php
- ThinkPHP中通过URL重写隐藏应用的入口文件index.php的相关服务器的配置
- apache 配置rewrite模块,URL中隐藏index.php
- 修改apache配置文件去除thinkphp url中的index.php
- 修改apache配置文件去除thinkphp url中的index.php
- ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php
- apache 配置虚拟目录+默认页+隐藏index.php
- ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php
- thinkPHP隐藏url地址栏中的index.php方法
- thinkPHP 从写URL配置掉index.php
- Ubuntu下配置ThinkPHP隐藏index.php
- url优化|隐藏index.php
- ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php
- apache服务器开启rewrite以及使用rewrite将thinkphp的url中index.php消除
- thinkphp在wamp 配置去掉url中index.php方法