从CodeIgniter url中删除index.php会重定向到localhost

时间:2015-01-21 08:34:56

标签: php .htaccess codeigniter url-rewriting

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

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

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

但是现在,当我想浏览http://localhost/job/seeker等网址时,我会看到http://localhost/上的Wampserver配置页面。

我该怎么办?

由于

5 个答案:

答案 0 :(得分:2)

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

并在application / config / config.php中设置

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

答案 1 :(得分:1)

以下代码取自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

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

还要确保再次正确设置Code Igniter配置,根据相同的链接编辑配置文件。

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

$config['index_page'] = "";

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

答案 2 :(得分:1)

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

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]

答案 3 :(得分:1)

试试这个:

     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]

答案 4 :(得分:0)

   **

删除index.php并将anyurl.com重定向到codeigniter中的www.anyurl.com

**

   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]