本文目錄一覽:
- 1、創建應用目錄後入口文件index.php應如何改寫
- 2、CI 框架怎麼去掉隱藏入口文件 index.php
- 3、thinkphp 入口文件為什麼是index.php
- 4、thinkphp 入口文件index.php
- 5、tp5框架index.php入口文件隱藏?
創建應用目錄後入口文件index.php應如何改寫
可以通過URL重寫隱藏應用的入口文件index.php
[ Apache ]
1. httpd.conf配置文件中載入了mod_rewrite.so模塊
2. AllowOverride None 將None改為 All
3. 把下面的內容保存為.htaccess文件放到應用入口文件的同級目錄下
IfModule mod_rewrite.cRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]/IfModule
[ IIS ]
如果你的伺服器環境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config,在中間添加rewrite節點:
rewriterulesrule name=”OrgPage” stopProcessing=”true”match url=”^(.*)$” /conditions logicalGrouping=”MatchAll”add input=”{HTTP_HOST}” pattern=”^(.*)$” /add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” /add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” //conditionsaction type=”Rewrite” url=”index.php/{R:1}” //rule/rules/rewrite
[ Nginx ]
在Nginx低版本中,是不支持PATHINFO的,但是可以通過在Nginx.conf中配置轉發規則實現:
location / { // …..省略部分代碼 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }}
如果你的ThinkPHP安裝在二級目錄,Nginx的偽靜態方法設置如下,其中youdomain是所在的目錄名稱。
location /youdomain/ { if (!-e $request_filename){ rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last; }}
——轉自ThinkPHP3.2.3開發手冊
CI 框架怎麼去掉隱藏入口文件 index.php
1.
LoadModule rewrite_module modules/mod_rewrite.so,把該行前的#去掉。
搜索 AllowOverride None(配置文件中有多處),看注釋信息,將相關.htaccess的該行信息改為AllowOverride All。
2.在CI的根目錄下,即在index.php,system的同級目錄下,建立.htaccess,直接建立該文件名的不會成功,可以先建立記事本文件,另存為該名的文件即可。內容如下(CI手冊上也有介紹):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
如果文件不是在www的根目錄下,例如我的是:,第三行需要改寫為RewriteRule ^(.*)$ /CI/index.php/$1 [L]。
另外,我的index.php的同級目錄下還有js文件夾和css文件夾,這些需要過濾除去,第二行需要改寫為:RewriteCond $1 !^(index\.php|images|js|css|robots\.txt)。
3.將CI中配置文件(system/application/config/config.php)中$config[‘index_page’] = 」index.php」;將$config[‘index_page’] = 」”; 。
這樣就可以了,不過千萬記得從啟apache。
如上的重定向規則在linux下也可以寫成一個.htacess文件。放到網站的根目錄。
thinkphp 入口文件為什麼是index.php
因為伺服器默認頁就是index.php, index.html。你在伺服器把默認頁設置為default.php。你的入口文件也可以是default.php
thinkphp 入口文件index.php
入口文件代碼的意義:
?php
/*第一層意義:
*定義的是與thinkphp有關的核心框架文件目錄路徑,它可以通過這一個常量在以後運行的時候都去找這個路徑,
*確保在以後運行過程中,絕對不會出現問題的(絕對不會對整個項目運行載入路徑產生錯誤);
*第二層意義:
*做一個操作(放跳牆),是防止用直接訪問我們的敏感文件,怎麼避免呢,我就可以做一個頁面包含整個
*敏感頁面,用戶的訪問必須通過頁面(A)來訪問,在A頁面處理好與安全相關的事宜 */
代碼:
?php
define(‘THINK_PATH’, ‘./ThinkPHP/’);
define(‘APP_NAME’, ’14’);
define(‘APP_PATH’, ‘.’);
require(THINK_PATH . “ThinkPHP.php”);
App::run();
?
tp5框架index.php入口文件隱藏?
一,找到/public/.htaccess文件,如果你的入口文件已經移動到根目錄下,那麼你的.htaccess文件也要剪切到根目錄下,總之要確保.htaccess跟入口的index.php保持同級。
二,根據你的php環境分別設置.htaccess文件:
Apache:
IfModule mod_rewrite.cOptions +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]/IfModule
phpstudy:
IfModule mod_rewrite.c Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
/IfModule
Nginx(在Nginx.conf中添加):
location / { // …..省略部分代碼
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/280666.html