【问题标题】:Codeigniter Htaccess configurationCodeigniter Htaccess 配置
【发布时间】:2016-01-05 15:05:45
【问题描述】:

我想配置我的 htaccess 文件,例如当我输入小写或大写的文件夹名称时,它将重定向到同一个文件夹。

目前我的文件为:

RewriteEngine on
#RewriteBase /ABC/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

问题是当我尝试访问我的控制器时,以小写形式给出文件夹名称,它找不到控制器。

如果我尝试abc/contrller_name/controller_function 它说找不到路径。 注意:在Windows系统上工作并使用XAMPP

【问题讨论】:

  • 我相信将路径转换为控制器/文件夹名称对于 php 来说比对于 apache imo 来说更重要

标签: php .htaccess codeigniter


【解决方案1】:

在 .htaccess 中

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

在 config.php (application/config)

$config['base_url'] = 'https://www.facebook.com/'; # set this to prevent HOST Injectio.
$config['index_page'] = '';

【讨论】:

    【解决方案2】:

    这是 Ubuntu/Debian 系统的程序。

    1. 在命令行中,键入 sudo su 以获取 root 权限。
    2. 纳米 /etc/apache2/mods-available/speling.conf
    3. 键入 CheckSpelling on 并按 ctrl-x, y 退出并保存文件。
    4. 键入 a2enmod,然后拼写并按 Enter。
    5. 键入 /etc/init.d/apache2 reload 以重新加载 apache。
    6. 输入错误的网址进行测试。

    来源making-apache-case-insensitive

    根据 Apache documentation,这是不可能的,因为 Windows 操作系统中嵌入了不区分大小写的功能。但是你可以“扭转问题”,让 Linux/Unix 下的 Apache 服务器不区分大小写。只需将以下指令添加到您的 .htaccess 中:

    RewriteEngine On
    RewriteMap lowercase int:tolower
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule .* index.php/$0 [PT,L]
    RewriteRule (.*) ${lowercase:$1} [R,L]
    

    【讨论】:

    • @Gautam:更新了答案。不过不确定。检查它是否有效。
    • @Gautam:它应该重定向您的网址并将其设为小写。进行更改后重新启动您的 apache。
    • 你能在我的代码中合并你的行集吗?因为我在服务器编程方面很弱。这将是一个很大的帮助
    • @Gautam:检查它是否有效。我的手很长。
    • 不工作它给我一个服务器错误。无论如何感谢您的努力
    【解决方案3】:

    修改.htaccess文件:

    RewriteEngine on
    RewriteCond $1 !^(index\.php|FolderName1|uploaded|images|css|js|robots\.txt)
    RewriteRule ^(.*)$ /foldername/index.php/$1 [L]
    

    注意:文件夹名称为htdocs path

    【讨论】:

      【解决方案4】:
      Options -Indexes
      RewriteEngine on
      
      RewriteBase /
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
      

      【讨论】:

        猜你喜欢
        • 2011-05-28
        • 1970-01-01
        • 2012-06-27
        • 1970-01-01
        • 2011-11-01
        • 1970-01-01
        • 2011-06-05
        • 2011-11-05
        • 2012-10-27
        相关资源
        最近更新 更多