简体   繁体   中英

CodeIgniter Mod_Rewrite issues

Having issues removing index.php? from the URL:

http://localhost/index.php?/reset_password

With htaccess file:

# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>

CI Settings:

$config['uri_protocol'] = 'AUTO';

I looked at the other threads on here with similar problems but none of their htaccess files work. Am I missing a setting?

I've never seen that .htaccess setup before, although it may work. I've used this for every CI project I've done, give it a try:

<IfModule mod_rewrite.c>

    RewriteEngine on

    # If the start of the URL doesn't match one of these...
    RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads)

    # Route through index.php
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

Add don't forget this in config.php :

/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';

And remember: This will not "remove" index.php from your URL automatically, but rather route the request through it if it isn't present. If you have hardcoded links with index.php in them, they'll have to be changed or you'll need additional .htaccess configuration. If you are using the CI url functions like base_url() , site_url() , and anchor() , they won't use index.php if you have it blank in your config above.

This code works for me:

If name of my site is codeIgniter_ci_intro

I used code in .htaccess

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

and I changed in config.php

$config['index_page'] = '';

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