【问题标题】:How to add one more file name in url before index.php dynamically set from front end in codeigniter?如何在codeigniter中从前端动态设置index.php之前在url中添加一个文件名?
【发布时间】:2019-02-21 06:07:06
【问题描述】:

1.初始网址ProjectName/English/index.php/controller1/function1

根据前端的要求

  1. ProjectName/French/index.php/controller2/function2

  2. ProjectName/German/index.php/controller3/function3

  3. ProjectName/Deutch/index.php/controller4/functioI4

我得到 htaccess 代码来删除 index.php 但无法让代码执行上述要求。

整个控制器都在一个 codeigniter 应用程序中。

【问题讨论】:

  • 为什么在前端切换语言时无法重定向到相应的 URL。
  • 在重定向中路径已更改,因此函数不会被执行,因为所有控制器都在一个 codeigniter 集中。
  • 这是一种不好的做法。如果你想改变语言,你应该用一个单独的函数来处理它。在这样的 URL 中发送语言 ProjectName/French/, ProjectName/German/ 不会有帮助,你不应该这样做。
  • 同一个工程下有多个控制器和函数。
  • 看看这里,慢慢了解这些概念...github.com/bcit-ci/CodeIgniter/wiki/…

标签: php codeigniter .htaccess


【解决方案1】:

在 routes.php 中使用路由如下 您的 url 调用将用于法语: ProjectName/French/controller2/function2 将调用 controller2 的 function2

$route['French/controller2/function2'] = 'controller2/function2';
$route['German/controller3/function3'] = 'controller3/function3';
$route['Deutch/controller4/function4'] = 'controller4/function4';

【讨论】:

    【解决方案2】:

    使用此代码从 .htaccess 文件中的 url 中删除 index.php。

    DirectoryIndex index.php
    order deny,allow
    #deny from all
    allow from all
    #allow from 116.193.161.42 103.212.0.0/16 61.95.235.67
    
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
     Header set Cache-Control "max-age=290304000, public"
    </FilesMatch>
    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>
    <IfModule mod_headers.c>
     Header set Access-Control-Allow-Origin "*"
    </IfModule>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2012-02-12
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 2019-11-20
      • 2019-02-14
      • 1970-01-01
      相关资源
      最近更新 更多