【问题标题】:Codeigniter URL rewriting not workingCodeigniter URL 重写不起作用
【发布时间】:2013-11-22 14:10:03
【问题描述】:

我正在使用以下 .htaccess 文件来重写没有 index.php 的 URL:

RewriteEngine on

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

该网站已上传到我的 VPS,当我进入时,假设:

http://1.1.1.1/~admin/ 

它工作正常。现在,当我想浏览网站时,例如:

http://1.1.1.1/~admin/welcome

它给了我以下错误信息:

The requested URL /home/admin/public_html/index.php/welcome was not found on this server.

现在,当我使用 URL 中的 index.php 访问欢迎控制器时:

http://1.1.1.1/~admin/index.php/welcome

它又可以正常工作了。这里出了什么问题?

【问题讨论】:

    标签: php .htaccess codeigniter url-rewriting


    【解决方案1】:

    我用这个:

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

    “?”在godaddy需要index.php之后。见此链接:https://github.com/EllisLab/CodeIgniter/wiki/Godaddy-Installation-Tips

    【讨论】:

      【解决方案2】:

      服务器上不存在路径/welcome,重写应该是这样的:

      RewriteRule ^(.*)$ index.php?$1 [L]
      

      【讨论】:

      • 重写应该通过将 Welcome 转换为参数 /home/admin/public_html/index.php?var1=welcome 来生成正确的路径
      • 它没有。它给了我这条消息:在此服务器上找不到请求的 URL /home/admin/public_html/index.php。
      • @Daan 不,OP 不需要 URL 参数,通常也不应该(因为 CI 默认为 url 段)。重写看起来不错,你在什么服务器上运行?
      • 一个使用 DirectAdmin 运行 CentOS 6.4 的 VPS。 Mod_rewrite 似乎工作正常,我还检查了 AllowOverride All 是否存在。
      【解决方案3】:
      <IfModule mod_rewrite.c>
      RewriteEngine On
      
      RewriteCond %{REQUEST_FILENAME} !-f
      
      RewriteCond %{REQUEST_FILENAME} !-d
      
      <IfModule mod_php5.c>
      RewriteRule ^(.*)$ index.php/$1 [L]
      </IfModule>
      
      <IfModule !mod_php5.c>
      RewriteRule ^(.*)$ index.php?/$1 [L]
      </IfModule>
      
      </IfModule>
      

      【讨论】:

        【解决方案4】:
        I wrote this: Trouble Shooting Codeigniter on localhost
        
        http://garyjohnson53.wordpress.com/2013/10/31/trouble-shooting-codeigniter-on-localhost/
        
        
        
        Its not a polished article, but it walks you through a few of the common things with codeigniter.
        
        MVC URI segments
        example.com/class/method/id/
        
        your condif.php usually in application/config
        your index.php
        your .htacess
        Alias and apache
        

        等等。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-01-09
          • 1970-01-01
          • 2016-12-18
          • 2023-03-24
          相关资源
          最近更新 更多