CodeIgniter: Unable to remove index.php from URL

2019-08-03 07:04发布

Having no luck removing the index.php file from the url.

For example I want to access the 'welcome' controller via http://domain.com/welcome

Currently getting a 404 error when attempting too.

However, at the moment I can only access is via http://domain.com/index.php/welcome

I have this currently in my .htaccess file which I got from the CI user guide:

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

I have the .htaccess file located in the directory above the application folder.

directory screenshot

Any help would be great.

1条回答
叼着烟拽天下
2楼-- · 2019-08-03 07:33

I have the following .htaccess

<IfModule mod_rewrite.c>
    AcceptPathInfo On

    RewriteEngine On

    ### Canonicalize codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    # RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
    # RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]

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

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

    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

</IfModule>

Also, please be sure that the AllowOverride directive of your httpd.conf is not set to None, since that would prevent your .htaccess rules to be readed.

查看更多
登录 后发表回答