删除/index.php/ CodeIgniter URL的一部分

时间:2014-05-17 07:06:07

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

我试图摆脱" index.php"在url中使用以下重写代码。但它不起作用 请帮我解决这个错误

# 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]

4 个答案:

答案 0 :(得分: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/

答案 1 :(得分:0)

使用此规则

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

答案 2 :(得分:0)

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

## 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>

答案 3 :(得分:0)

这个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]