简体   繁体   中英

Removing index.php from CodeIgniter url redirects to localhost

I'm developing with WampServer and tried to remove index.php from CodeIgniter urls. Added these lines to .htaccess file as I saw in ellislab website: https://www.codeigniter.com/user_guide/general/urls.html

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

This is the root of my website: http://localhost/job/

But now when I want to navigate urls like http://localhost/job/seeker I see the Wampserver config page that is on http://localhost/ .

What can I do?

Thanks

RewriteEngine on
RewriteBase /job
RewriteCond $1 !^(index\.php|images|table-images|robots\.txt|styles|js|uploads)
RewriteRule ^(.*)$ index.php/$1 [L]

and set in application/config/config.php

$config['base_url'] = 'http://127.0.0.1:8000/job/';
$config['index_page'] = 'index.php';

The following code is taken from http://www.farinspace.com/codeigniter-htaccess-file/

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

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

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$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]

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

Ensure the .htaccess file is named correctly and in the same directory as your index.php file and that mod_rewrite is enabled in Apache on your server stack.

Also ensure you set your Code Igniter config correctly again, according to the same link, edit your config file.

$config['index_page'] = "index.php";

to

$config['index_page'] = "";

Also, please use search. This question pops up quite a bit in many places with answers every where.

it happens in wamp server try this

RewriteEngine On
RewriteBase /name_of_your_project
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Try this:

     RewriteEngine On
     RewriteBase /projects/hc/homecare/trunk/homecare 
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system)
     RewriteRule ^(.*)$ /projects/hc/homecare/trunk/homecare/index.php?/$1 [L]
   **

Remove index.php and redirect anyurl.com to www.anyurl.com in codeigniter

**

   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule .* index.php/$1 [PT,L]
   RewriteCond %{HTTP_HOST} !^www\.
   RewriteCond %{HTTPS}s on(s)|offs()
   RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R] 

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