【问题标题】:Remove /index.php/ part of CodeIgniter URLs删除 /index.php/ 部分 CodeIgniter URL
【发布时间】:2014-07-05 16:37:58
【问题描述】:

我尝试使用以下重写代码摆脱 url 中的“index.php”。但它不起作用 请帮我修复这个错误

# Development
RewriteEngine On
RewriteBase /mvcTestApp/blog/ciBlog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|scripts|styles|vendor|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

【问题讨论】:

  • 您能否也发布 Apache 访问/错误日志,或者至少说明什么不起作用。

标签: php .htaccess codeigniter mod-rewrite url-rewriting


【解决方案1】:

在 .htaccess 文件中,添加以下内容。

#Rewrite index.php
#Start using rewrite engine
RewriteEngine On
#Rewrite condition
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#Whenever index.php is there in the url, it will rewrite to / automatically
RewriteRule .* index.php/$0 [PT,L]

查看此链接了解更多详情:http://subhra.me/remove-index-php-urls-codeigniter/

【讨论】:

    【解决方案2】:

    这个 htaccess 对我有用。试试这个。

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

    【讨论】:

      【解决方案3】:

      使用此规则

      RewriteEngine on
      RewriteCond $1 !^(index\.php|images|robots\.txt)
      RewriteRule ^(.*)$ /index.php/$1 [L]
      

      最后一条规则中“index.php”之前缺少"/"

      或参考网址

      http://ellislab.com/codeigniter/user-guide/general/urls.html

      【讨论】:

        【解决方案4】:

        这是我的 CodeIgniter 重写规则套件。请阅读内联 cmets:

        ## Rewrite rules
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteBase /
        
            # Remove the "index.php" part of URI
            # Remove access to "codeigniter" and "data" folders
            RewriteCond %{REQUEST_URI} ^(codeigniter|data).*
            RewriteRule ^(.*)$ /index.php?/$1 [L]
        
            # Block access to "hidden" directories whose names begin with
            # a period. e.g. .git, .svn
            RewriteCond %{SCRIPT_FILENAME} -d
            RewriteCond %{SCRIPT_FILENAME} -f
            RewriteRule "(^|/)\." - [F]
        
            # WWW redirect
            RewriteCond %{HTTP_HOST} ^(?!www\.).*
            RewriteCond %{HTTP_HOST} ^(?!dev\.).*
            RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,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 the root index.php.
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?/$1 [L]
        </IfModule>
        

        【讨论】:

          猜你喜欢
          • 2016-05-14
          • 2014-10-28
          • 2012-06-15
          • 2012-09-21
          • 2011-10-12
          • 1970-01-01
          • 2017-01-31
          相关资源
          最近更新 更多