0

我有在 url 中都包含 /main/ 的 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>

我正在使用几个控制器,我的链接类似于这个:

谢谢

4

1 回答 1

3

尝试这个:

 $route['blog'] = 'blog';  // seem stupid but otherwise the (:any) route below will send it to main
  $route['blog/(:any)'] = 'blog/$1'; // to have blog cotroller work
  $route['blog/(:any)/(:any)'] = 'blog/$1/$2';
  // repeat for other controllers

 $route['(:any)'] = "main/$1";
 $route['(:any)/(:any)'] = "main/$1/$2"; // if you use other uri parameter
 $route['default_controller'] = 'main'; // to have your main page work...

并将所有对其他控制器的调用放在此指令之前,因为这将阻止所有其他控制器调用。

于 2012-11-08T22:19:15.057 回答