我有网址中的所有包含/ 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