[英]Rename URL in Codeigniter
我想從我的/public/index.php
和 Bonfire 項目 URL 中刪除/public/index.php
..
我當前的網址: http://localhost/public/index.php/page
想要的網址: http://localhost/page
但我希望鏈接、圖像和機器人的路徑完好無損! 如何做到這一點? 任何使用 .htaccess 的好資源?
嘗試閱讀CodeIgniter URLs 中的“刪除 index.php 文件”小節:
在 .htaccess 中
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
在 config.php 中:
$config['index_page'] = '';
你能試試這個嗎?
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
這對我來說很好用
我認為您必須采取以下步驟:
將您的 .htaccess 文件從應用程序轉移到根目錄
刪除/注釋舊文件中的舊代碼(使用#)並粘貼到下面的代碼中
RewriteEngine on #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] RewriteRule ^/?ajax/(.*)$ ajax.php? $1 [NC,QSA,L]
針對 $config['index_page'] 從配置文件中刪除 index.php,如下所示 $config['index_page'] = '';
然后從Apache激活重寫模塊
它應該適合你。
您將 .htaccess 文件從我認為的應用程序復制到您的 basedir 中。
或者將新的 .htaccess 添加到您的 basedir。
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.