.htaccess - 使用 htaccess 文件删除 ubuntu 上 codeigniter 中的 index.php

标签 .htaccess codeigniter mod-rewrite

使用Windows 7上安装的Apache2,我使用下面的htaccess配置从codeigniter url中删除index.php:

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

有人可以告诉我为什么上面的配置在 ubuntu 上不起作用吗? 我已使用 sudo a2enmod rewrite 启用 mod 重写。谢谢

最佳答案

这可能是因为 ubuntu 服务器设置为传递 PATH_INFO,这意味着您不需要查询字符串。您可能只需从规则中删除 ? 就可以了:

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

关于.htaccess - 使用 htaccess 文件删除 ubuntu 上 codeigniter 中的 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18365829/

相关文章:

php - 如何使用 Codeigniter 在浏览器中查看 XML 文件

mysql - 如何通过 POST 从选择数据表的选项中获取值(value)

php - 如何使用 .htaccess 保护服务器目录

apache - 强制通过 HTTPS 进行 HTTP 身份验证

php - 友好的 url 不聪明

php - Codeigniter 数据库错误编号 1048 值显示 NULL,即使它们不是 NULL

.htaccess - Codeigniter安装在子目录中

php - https ://to Http rewrite in . htaccess

Apache Mod_Rewrite 问号

html - .htaccess 使用别名 url 重定向