在codeigniter

时间:2015-08-11 19:09:17

标签: php .htaccess codeigniter mod-rewrite

我在.htaccess文件

中有这个
<IfModule mod_rewrite.c>    
Options +FollowSymLinks     
Options -MultiViews

RewriteEngine On    
RewriteBase /   
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d     
RewriteRule ^.+$ /index.php [L]
</IfModule>

我的网站显示所有网页文件index.php内的文件。我试图摆脱必须放入mysite/index.php/filename并直接转到mysite/filename

我的网址是http://local-news.today/subscribe。当我使用此地址local-news.today/index.php/subscribe时,它会显示订阅功能上的内容。

我的网站托管于godaddy。我也使用codeigniter。任何帮助将不胜感激。

5 个答案:

答案 0 :(得分:1)

我在htaccess文件中完成了以下操作:

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

这适合我。

答案 1 :(得分:1)

将以下代码放入.htaccess

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

并在application / config / config.php中找到以下行

$config['index_page'] = "index.php"

并将其替换为以下代码

$config['index_page'] = ""

答案 2 :(得分:1)

简单搜索&#34; codeigniter mod_rewrite htaccess&#34;告诉我this gist

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

所以基本上你的重写规则有点不对劲。你需要像

这样的东西
RewriteRule ^(.*)$ index.php?/$1 [L]

这是什么意思? ^(.*)$将所有内容((.*))从开头(^)到结尾($)进行匹配,并使用$1将其附加到 index.php ?/

在您的示例中,您忘记将其附加到网址的末尾...

答案 3 :(得分:1)

根据我的经验,在共享主机上,您经常需要使用.htaccess文件。这通常对我有用:

RewriteEngine on
RewriteBase /

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

但是你会注意到这里的最后一行与其他答案不同,? {<1>}之后 {而不是之前(或根本没有) 。因此,请尝试将其作为基础/,然后根据需要修改最后一行。可能还需要删除.htaccess行。

答案 4 :(得分:1)

我总是使用这个,它就像一个魅力:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>