thinkPHP Apache 最佳化url,隱藏index.php所需配置____PHP

來源:互聯網
上載者:User

例如原先路徑為: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 onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfModule>


完成以上四步就大功告成了。

註:發現在第三步中,將URL_MODEL=>1的時候也是可以的,我用的是thinkphp3.1




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.