【问题标题】:Hiding Default Controller Name in Codeigniter在 Codeigniter 中隐藏默认控制器名称
【发布时间】:2012-06-21 13:24:00
【问题描述】:

我的网站第一次打开时,直接转到这个地址:http://www.website.com/tr/main

但我希望我的链接是这样的:http://www.website.com/ 我无法删除“tr/main”链接。我该如何解决这个问题?

PHP 代码:

$route['default_controller'] = "main";
$route['404_override'] = '';
$route['(tr|en)/(.+)$'] = '$2';
$route['(tr|en)$'] = $route['default_controller'];

Htaccess 代码:

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]  

【问题讨论】:

    标签: php codeigniter routing


    【解决方案1】:

    在你的 config.php 文件中写下这段代码:-

    $config['base_url']='http://Your Path/';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';
    $config['subclass_prefix'] = 'Base';
    

    在你的 routes.php 文件中写下这段代码:-

    $route['default_controller'] = "home";
    $route['404_override'] = '';
    

    【讨论】:

    • 你是在 localhost 上运行你的项目吗?
    • 现在“tr/main”链接不会出现。主页链接已解决,但这次其他链接不起作用。单击其他链接时,“tr”链接不会出现,因此除主页外的其他链接不起作用。顺便说一句,我不在本地主机上。
    • 你可以为其他链接编写代码吗?假设你是 tr(button) 的链接将是
    • @YunusEmre:如果这个答案有帮助,请点赞。如果它解决了您的问题,请mark it as accepted
    【解决方案2】:

    在您的 routes.php 文件中编写以下代码:-

    $route['default_controller'] = "main";
    $route['404_override'] = '';
    

    然后在您的“主”控制器中,即在 main.php 中使用

    function index() 
    {
        // write all your code inside this function    
    }
    

    【讨论】:

    • 如果你知道了请告诉我
    • 我已经在使用您编写的相同代码了。我必须更改 config.php 文件中的任何内容吗?
    • 你能把这段代码删掉吗 $route['(tr|en)/(.+)$'] = '$2'; $route['(tr|en)$'] = $route['default_controller'];然后尝试
    • 你能告诉我你在 $config['base_url']= 的 config.php 文件中写了什么吗?
    • 它是空白的。里面什么都没写。
    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    相关资源
    最近更新 更多