CodeIgniter in subdomain folder, removing the inde

2019-06-08 03:31发布

问题:

So I am trying to remove index.php from address using this manual: http://dev.lohv.eu/1/user_guide/general/urls.html

Atm I have address http://dev.lohv.eu/1/index.php but I want to use it in future without index.php, like so: http://dev.lohv.eu/1/

I created .htaccess file according to manual:

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

But unfortunaly it fails, I get 404 error. I guess the problem is, I am trying to configure .htaccess in subdomain folder so it wont fit as in manual and needs some extra, but I don't know what extras it needs.

回答1:

I think you're missing a '?'. RewriteRule ^(.*)$ /index.php?/$1 [L]

This is CI's recommended .htaccess template (or at least it was a year ago), and that ? is the major difference between the two.

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

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