0

这是我的 codeigniter .htaccess 文件,我成功地将 index.php 替换为方法名称。但我想从 url 中强制删除 index.php,即如果有人在 url 中添加 index.php,我想使用 .htaccess 删除它。喜欢=>http://localhost/project/index.php/welcome到=>http://localhost/project/welcome

该项目仍在xampp中进行开发。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /project
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L] 

    # Enforce NO www
    RewriteCond %{HTTP_HOST} ^www [NC]
    RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
    </IfModule>
4

2 回答 2

1
<IfModule mod_rewrite.c>
    RewriteEngine On
    #my url is http://localhost/project
    #RewriteBase /project/
    #set your own
    RewriteBase /project/

    #Redirect if index.php exist to without index.php
    RewriteRule ^index.php/(.*)$  $1 [R=301,L] 

    #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>
于 2013-07-20T09:43:47.077 回答
0

试试这个代码:

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

看看这篇文章

于 2013-07-20T08:48:53.610 回答