【问题标题】:How to remove index.php in url while working on Codeigniter-WAMP如何在使用 Codeigniter-WAMP 时删除 url 中的 index.php
【发布时间】:2018-03-02 15:15:02
【问题描述】:

我已经看到很多关于我的问题的问题,我尝试了很多解决方案!我从 24 小时开始就面临这个问题并且无法继续前进。

我采取的这些步骤很简单。

1) 安装 codeigniter。 2) 通过删除 #sign.in appache httpd.conf 文件来启用 rewrite_mod 3)confing.php文件中的这些变化

$config['base_url'] = 'http://localhost/ciblog'; $config['index_page'] = '';

4)www/ciblog 文件夹中的新 .htaccess 文件,其中包含这些行

RewriteEngine on

RewriteCond $1 !^(index\.php|assets|images|js|css|
uploads|favicon.png)

RewriteCond %(REQUEST_FILENAME) !-f

RewriteCond %(REQUEST_FILENAME) !-d

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

它会出现一个错误 “在此服务器上找不到请求的 URL /ciblog/welcome。”

请特别帮助我,我正在使用 WAMP 服务器。

提前致谢。

【问题讨论】:

  • 修改配置后是否重启了apache?
  • 你启用了 apache mod_rewrite wamp
  • 是的,我已经重新评估了 apache,并且我已经启用了 mod_rewrite

标签: php apache .htaccess codeigniter codeigniter-3


【解决方案1】:

设置VHOST

/etc/hosts(或c:/windows/system32/drivers/etc/hosts)中添加:

127.0.0.1 dev.whatever.com

然后,在 Apache 的conf/extra/httpd-vhosts.conf 中,设置你的VirtualHost,下面是一个例子:

<VirtualHost *:80>
    DocumentRoot "/var/www/bonemvc/public"
    ServerName dev.whatever.com
    FallbackResource index.php
    <Directory "/var/www/bonemvc">
        DirectoryIndex index.php
        Options -Indexes +FollowSymLinks
        AllowOverride none
        Require all granted
    </Directory>
    BrowserMatch ".*MSIE.*" nokeepalive downgrade-1.0 force-response-1.0
</VirtualHost>

最后,打开 Apache 的 httpd.conf 并查找 vhost,取消注释该行以便加载其他 conf 文件。

关闭浏览器,重新启动 apache,重新打开浏览器,然后前往 http://dev.whatever.com。您应该在没有显示 index.php 的情况下获得您的主页!

【讨论】:

  • 不工作我在 http-vhosts.conf 文件中添加了这个代码 ServerAdmin webmaster@localhost DocumentRoot "c:\wamp\www" ServerName localhost ErrorLog "logs/localhost-error. log" CustomLog "logs/localhost-access.log" common ServerName localhost DocumentRoot "c:\wamp\www\ciblog\public" SetEnv APPLICATION_ENV "development" DirectoryIndex index.php AllowOverride all Order Allow, Deny Allow from all
  • 并在 httpd.conf 中取消注释此行包括 conf/extra/httpd-vhosts.conf 并且我检查了 127.0.0.1 localhost 行是否存在于 (c:/windows/system32/drivers/etc/主机)
  • 您的 DocumentRoot 和 Directory 错误。仔细看看我的!
  • 嘿!现在我通过简单的(localhost)访问这个地址::(localhost/ciblog/index.php/welcome) 请指导我哪里有问题。现在我无法访问 localhost 主页。
  • ServerName localhost DocumentRoot "c:/wamp/www/ciblog/" 选项 +索引 +包括 +FollowSymLinks + MultiViews AllowOverride All 需要本地
【解决方案2】:

尝试使用以下 htaccess

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

而且你还需要搜索和替换

$config['uri_protocol'] ="AUTO"

$config['uri_protocol'] = "REQUEST_URI"

在 config.php 中

【讨论】:

  • 和这个没有区别 .htaccess $config['uri_protocol'] = "REQUEST_URI" 这行已经有这个值了。
  • @Moneeb 添加一个像这样的“/” $config['base_url'] = 'localhost/ciblog'; .并在重新启动 wamp 后尝试。因为您更改了 apache 配置。
【解决方案3】:

.htaccess 文件中尝试以下代码: 重写引擎开启 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我希望这适用于 xampp 和 wamp 服务器 如果您仍然有问题,请与我分享详细信息。

【讨论】:

    猜你喜欢
    • 2011-10-28
    • 1970-01-01
    • 2014-08-19
    • 2015-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-08-15
    • 2012-08-10
    • 2015-10-24
    相关资源
    最近更新 更多