我有網址中的所有包含/ main /的url,因爲它是我的主控制器。 我想擺脫它。如何使用CodeIgniter刪除URL中控制器的名稱?
我在用戶指南中明白,路由類只會重新路由我的URL,而不是隱藏其中的一部分(根據它們的文章,它是段1)。 因此,我發現這一點:
$route['(:any)'] = "auth/$1";
但我有404錯誤(這是我作出routing.php的唯一修改)
我相信我會做在.htaccess ,但我不知道應該是什麼語法。現在,我的.htaccess是這個:
<IfModule mod_rewrite.c>
SetEnv MAGIC_QUOTES 0
SetEnv PHP_VER 5
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks -MultiViews
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
DirectoryIndex index.php
#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]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
我使用幾個控制器和我的鏈接是類似這樣的:
感謝
不能幫助,如果你不發佈htaccess和routes.php,並確切地告訴我們你想要什麼。路由首先通過htaccess然後通過routes.php設置,因此您需要首先檢查htaccess。通常你只需要讓htaccess從你的uri中刪除index.php。同樣在你的例子中,你將所有的控制器調用路由到你的認證控制器,但你也說你想讓它到主控制器? – jtheman
謝謝,請參閱編輯 –
沒有什麼我在htaccess中可以看到會導致意外404.因此,你應該能夠通過routes.php實現你想要的。你能解釋一下你的具體情況,以及你是如何構建你的uri和控制器的嗎?與CI一起工作的越多,您需要的路由就越少,這是我的經驗,因爲您可以使用有意識的結構來構建您的控制器。 (URI:控制器/函數/參數(s)),那麼你只需要讓你的默認控制器(主要在你的情況下)具有索引功能顯示網站主頁) – jtheman