【问题标题】:remove index.php in codeigniter with wamp not working在 wamp 不工作的情况下删除 codeigniter 中的 index.php
【发布时间】:2016-02-14 18:34:56
【问题描述】:

我在使用 Wamp Server 从 Codeigniter 3 中的 url 中删除 index.php 时遇到问题。我是在文件 config.php (project_folder/application/config/config.php) 中更改

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = "REQUEST_URI";

并使用编写的代码创建与应用程序文件夹相同级别的 .htaccess 文件

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# If your website begins from a folder e.g localhost/my_project then 
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /

# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>

rewrite_module 开启,我的虚拟主机代码是

<VirtualHost *:80> 
    DocumentRoot "D:/work/project_Name/" 
    ServerName abc.local 
    <Directory "D:/work/project_Name/"> 
       Order Allow,Deny
       Allow from all
       Require all granted
    </Directory>
</VirtualHost>

使用这些更改和代码我的项目在没有 index.php 和错误抛出的情况下无法运行

abc.local/controllername
Not found
The requested URL /controllername/ was not found on this server.

谢谢!

【问题讨论】:

  • 阅读本教程w3code.in/2015/09/…
  • 上述问题已通过更改虚拟主机文件 httpd-vhosts.conf ( C:\wamp\bin\apache\apache2.4.9\conf\extra ) 解决。通过替换“Order Allow,拒绝”变成“所有人允许” 干杯!

标签: php .htaccess codeigniter url


【解决方案1】:

在 .htaccess 文件上试试这个代码

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

config.php 页面设置$config['base_url'] ="http://localhost/project/"$config['index_page'] = '';$config['uri_protocol'] = 'AUTO';

【讨论】:

  • 点击 Wampserver 并选择 apache->httpd.conf 并从 #LoadModule rewrite_module modules/mod_rewrite.so 中删除 #。最后重启 Wamp 服务器
【解决方案2】:

试试这些:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folder_name_of_project/


    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]


    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|stylesheets|javascript)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule> 

【讨论】:

    猜你喜欢
    • 2011-10-28
    • 2014-08-19
    • 2015-10-27
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 2016-10-09
    • 2014-11-21
    相关资源
    最近更新 更多