简体   繁体   中英

code igniter can't remove index.php from URL

I have my codeigniter library under a folder called 'codeigniter' (very original) so I visit it at this address which loads fine, http://mysite.co.uk/codeigniter/index.php/pages/view/about

However I can't get to my 'about' page using the following address http://mysite.co.uk/codeigniter/pages/view/about URL without the 'index.php' in the address, it keeps hitting my default controller instead of my pages controller.

I've updated the following:

config.php

$config['base_url'] = 'http://mysite';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

.htaccess

RewriteEngine on
RewriteBase /codeigniter/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Any help would be great!

确保将“ AllowOverride All”放置在Apache配置文件中,以使.htaccess正常工作。

You can Use This in your .htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L]

You can use this in your .htaccess file

Options -Indexes 
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
        #RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
        #RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
        #RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]
</IfModule>  
#Gzip
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
<IfModule mod_headers.c>
Header add Cache-Control:  "no-store, no-cache, must-revalidate"
Header unset Pragma
FileETag None
Header unset ETag
</IfModule>
#End Gzip
# BEGIN Expire headers  
<ifModule mod_expires.c>  
    ExpiresActive On  
    ExpiresDefault "access plus 5 seconds"  
    ExpiresByType image/x-icon "access plus 2592000 seconds"  
    ExpiresByType image/jpg "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"  
    ExpiresByType image/gif "access plus 2592000 seconds"  
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType text/html "access plus 600 seconds"  
    ExpiresByType text/css "access plus 604800 seconds"  
    ExpiresByType text/javascript "access plus 216000 seconds"  
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"  
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/javascript "access plus 216000 seconds"  
    ExpiresByType application/x-javascript "access plus 216000 seconds"  
    ExpiresByType application/xhtml+xml "access plus 600 seconds"  
</ifModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM