【问题标题】:CodeIgniter URL Rewrite IssueCodeIgniter URL 重写问题
【发布时间】:2013-11-27 02:21:55
【问题描述】:

我正在使用 codeigniter 制作应用程序,现在正在上传到 GoDaddy 服务器但收到 404 错误。

我的代码是这样的

$config['index_page'] = "index.php?";
$config['uri_protocol'] = "QUERY_STRING";

.htaccess 文件是

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

我得到了类似的价值

http://yourdomain.com/index.php?controller/action/etc

但我需要

http://yourdomain.com/controller/action/etc

请帮忙。

【问题讨论】:

  • RewriteRule ^(.*)$ /index.php/$1 [L]
  • godaddy 网址中的@Hussaintamboli 就像.../index.php?..
  • 我不知道godaddy url,但是要在CI 中传递http://yourdomain.com 之后的所有内容,请执行上述操作。如果您想为 images 添加一些例外,即您不希望 http://yourdomain.com/images/image.png 遵循上述规则,请将其放在其上方 - `RewriteCond $1 !^(index\.php|images)`

标签: .htaccess codeigniter url-rewriting


【解决方案1】:

试试这个

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule> 

【讨论】:

  • 但是这个答案中是否需要+FollowSymLinks?对于@chirag
  • @hussain tamboli:没有
  • @chirag 好的。不要忘记在 /etc/apache2/sites-enabled/Directory 指令中使用 AllowOverride All。这样.htaccess就启用了
【解决方案2】:

试试

$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";

【讨论】:

  • 你启用了 mod_rewrite 吗?
  • RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L]
  • 为您的 htaccess 尝试一下
【解决方案3】:

试试这个......它应该可以工作。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /sgu_portal
RewriteCond $1 ^(application|system|private|logs)
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
RewriteCond $1 ^(index\.php|css|js|images|img|less|player-skin|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

输入您的文件夹 CSS,js,images 或其他。如果不是你的 css 不工作。

RewriteRule ^(.*)$ - [PT,L]
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>

在 CI 配置中

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

【讨论】:

    【解决方案4】:

    参考这个答案

    https://stackoverflow.com/a/16558169/1182195

    确保您的服务器配置设置为

    1 . 启用模组重写

    2 。 允许在你的 apache 中覆盖 htaccess

    【讨论】:

      【解决方案5】:

      谢谢大家的回答非常感谢,但正确的答案是这样的 htaccess文件的代码是这样的

      Options -Indexes
      Options +FollowSymLinks
      Options -MultiViews
      DirectoryIndex index.php
      <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
      </IfModule>
      <IfModule !mod_rewrite.c>
        ErrorDocument 404 index.php
      </IfModule>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-24
        • 1970-01-01
        • 2019-12-06
        • 2016-01-09
        • 2014-01-10
        • 2015-11-12
        • 1970-01-01
        相关资源
        最近更新 更多