導航:首頁 > 編程語言 > apache去掉indexphp

apache去掉indexphp

發布時間:2024-10-22 05:41:59

A. 網址中間的index.php怎麼去掉,看了一些回答不知道怎麼做,希望能回答,解決了多給分,一定的。

使用URL重寫,可以使網站的URL屏蔽index.php這種不友好的網址。
假如你的web伺服器端使用的是apache,那麼你需要開啟mod_rewrite.so模塊,
為網站在apache配置文件中的<Directory>配置節添加如下內容,
Options FollowSymLinks
AllowOverride ALL
Order allow,deny
Allow from all
然後在網站根目錄下創建一個 .htaccess 文件,內容如下
<IfMole mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfMole>

就可以在網址中屏蔽index.php了

B. url怎麼去掉index.php

要移除URL中的"index.php",可以通過以下步驟實現:

1. 啟用「mod_rewrite」:在Apache配置文件(通常為"conf/httpd.conf")中找到"LoadMole rewrite_mole moles/mod_rewrite.so"一行,去除行首的「#」以啟用mod_rewrite模塊。

2. 編寫.htaccess規則:在Apache根目錄下創建或編輯.htaccess文件,添加以下規則:

<IfMole mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

</IfMole>

上述規則定義了一個重寫規則,當請求匹配非目錄或非文件路徑時,將該路徑重定向到"index.php"並附帶原始路徑參數。

若在CodeIgniter根目錄下存在如css、js等子目錄,需調整.htaccess規則以正確處理這些路徑,規則可能如下:

<IfMole mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond $1 !^(index\.php|images|css|robots\.txt)

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

</IfMole>

該規則排除了"index.php"、"images"、"css"和"robots.txt"文件,確保其他路徑正確重定向至"index.php"。

C. 加了.htaccess文件為什麼仍不能去掉index.php

1. 在httpd.conf中,將 所有 AllowOverride None 改為 AllowOverride All 好像共有三處吧,然後重啟apache2. 在.htaccess文件中,是這樣的配置:RewriteEngine onRewriteCond $1 !^(index\.php|robots|stafile|upload|\.txt)RewriteRule ^(.*)$ /index.php/$1 [L]如果你是直接在根目錄配置的,則以上就可以了;假如你的項目在根目錄底下一層,則 RewriteRule ^(.*)$ /index.php/$1 [L] 得變為 RewriteRule ^(.*)$ /項目文件夾名/index.php/$1 [L]以上兩步已經可以去掉 index.php了,假如項目中的路徑,為了去掉index.php,還需要第 3 步 操作,因為第 3 步 是影響到 site_url();這個函數的。

閱讀全文

與apache去掉indexphp相關的資料

熱點內容
電視看籃球app哪個好 瀏覽:47
高中畢業當程序員 瀏覽:245
php標簽屬性大全 瀏覽:897
遠程訪問伺服器ip地址 瀏覽:312
程序員吃雞蛋炒菜 瀏覽:173
在哪裡看俄羅斯電視劇app 瀏覽:308
怎麼找資料庫伺服器地址 瀏覽:487
伺服器調試怎麼翻譯 瀏覽:921
php如何處理ajax請求 瀏覽:211
php數組下標存在 瀏覽:707
php獲取ip歸屬地 瀏覽:175
撩女程序員怎麼辦 瀏覽:508
百度伺服器做什麼 瀏覽:193
打開軟體加速伺服器有什麼危害 瀏覽:87
php去除數組下標 瀏覽:794
ipad的app內容哪裡看 瀏覽:284
遇見空間app在哪裡 瀏覽:547
用命令對一個文件內容進行統計 瀏覽:317
華為交換機配置命令縮寫 瀏覽:344
鏈接伺服器出現問題怎麼處理 瀏覽:834