从 CodeIgniter url 中删除 index.php 重定向到本地主机

Removing index.php from CodeIgniter url redirects to localhost

我正在使用 WampServer 进行开发,并试图从 CodeIgniter 网址中删除 index.php。正如我在 ellislab 网站上看到的那样,将这些行添加到 .htaccess 文件中: https://www.codeigniter.com/user_guide/general/urls.html

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

这是我网站的根目录: http://localhost/job/

但是现在当我想导航像 http://localhost/job/seeker I see the Wampserver config page that is on http://localhost/.

这样的 URL 时

我能做什么?

谢谢

以下代码摘自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/?$  [L,R=301]

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

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

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

确保 .htaccess 文件命名正确并且与您的 index.php 文件位于同一目录中,并且在您的服务器堆栈上的 Apache 中启用了 mod_rewrite。

同时确保您再次正确设置您的 Code Igniter 配置,根据相同的 link,编辑您的配置文件。

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

$config['index_page'] = "";

另外,请使用搜索。这个问题在很多地方都出现了很多,到处都有答案。

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

并设置在application/config/config.php

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

它发生在 wamp 服务器中试试这个

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

试试这个:

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

删除 index.php 并在 codeigniter

中将 anyurl.com 重定向到 www.anyurl.com

**

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