【问题标题】:CodeIgniter htaccess mod_rewrite not working properlyCodeIgniter htaccess mod_rewrite 无法正常工作
【发布时间】:2012-05-07 17:58:44
【问题描述】:

我正在尝试将网址设置为 http://127.0.0.1/dev/blog/welcome 但是当我输入它时,它会将 url 更改为 http://127.0.0.1/dev/blog/index.php/welcome

但是当我使用http://127.0.01/dev/blog//welcome 时,出于某种原因,它会保持这种状态。

我的 .htaccess 是

RewriteEngine On
RewriteBase /dev/blog
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]

我的 config.php 已经配置好了

$config['base_url'] = 'http://127.0.0.1/dev/blog/';
$config['index_page'] = '';

哦,我确实检查了 mod_rewrite 是否打开并且我正在使用 WAMP

另一个信息:我正在使用 Firefox,但是当我使用 IE(9) 时,它不会更改 url http://127.0.0.1/dev/blog/welcomehttp://127.0.0.1/dev/blog/index.php/welcome

【问题讨论】:

  • 愚蠢的问题,但是您是否尝试过刷新浏览器缓存?
  • @Zenbait 是的,我做了 ctrl+f5,shift+ctrl+r,清除我的缓存。

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

对于您的 RewriteRule,添加 NC 和 QSA 标志。 QSA 确保附加查询字符串。除非您计划在 CodeIgniter 上管理您的 css 文件、图像和 robots.txt,否则也请省略倒数第二行。

试试这个:

RewriteEngine On
RewriteBase /dev/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]

另外,请在 config.php 中检查您的 uri_protocol。我遇到了一些 WAMP 无法正确检测到它的问题,并且最幸运的是将其设置为 PATH_INFO 而不是 AUTO

【讨论】:

  • 当我做http://127.0.0.1/dev/blog/welcome时,页面似乎说“没有指定输入文件。”
【解决方案2】:

您是否在 apache 配置中将 AcceptPathInfo 设置为 ON

【讨论】:

    【解决方案3】:

    确保您在 webroot 目录而不是应用程序目录上编辑文件。我一直在努力让它正常工作,直到我最终发现这是我的问题

    【讨论】:

      猜你喜欢
      • 2012-08-05
      • 2011-12-27
      • 2014-03-02
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多