apache 如何在 wamp 上配置 codeigniter mod_rewrite?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1014547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:46:44  来源:igfitidea点击:

how to configure codeigniter mod_rewrite on wamp?

apachemod-rewritewamp

提问by Emil Hajric

Hi guys could you please tell me how can I configure codeigniter mod_rewrite on wamp?

嗨,伙计们,你能告诉我如何在 wamp 上配置 codeigniter mod_rewrite 吗?

I've tried enabling it through the wamp menu(wamp-->apache-->apache modules-->rewrite module) and restarting wamp but it's like nothing happened.

我已经尝试通过 wamp 菜单(wamp-->apache-->apache modules-->rewrite module)启用它并重新启动 wamp,但它就像什么也没发生。

I'm asking you guys this cause I need to get rid of the index.php in my codeigniter urls through .htaccess

我问你们这是因为我需要通过 .htaccess 删除我的 codeigniter url 中的 index.php

回答by M. Ahmad Zafar

There are total 4 easy steps that you need to follow (I am considering you have WAMP installed on C:\wampand CodeIgniter has been to extracted to C:\wamp\www\codeigniter\):

您总共需要遵循 4 个简单的步骤(我认为您已经安装了 WAMPC:\wamp并且 CodeIgniter 已被提取到C:\wamp\www\codeigniter\):

  1. Create a .htaccess file as mentioned in http://codeigniter.com/wiki/mod_rewritebut replace RewriteBase /with RewriteBase /codeigniter/according to your path.
  2. Place this file in C:\wamp\www\codeigniter\folder
  3. Open the httpd.conf file either from WAMP->Apache->httpd.confor manually from C:\wamp\bin\Apache\conf\httpd.confthen locate the line #LoadModule rewrite_module modules/mod_rewrite.soand replace the hash(#) from the beginning so that the complete line becomes LoadModule rewrite_module modules/mod_rewrite.so. Now Restart Apache.
  4. Finally open the file C:\wamp\www\codeigniter\application\config\config.phpand replace $config['index_page'] = "index.php";with this $config['index_page'] = "";
  1. 创建一个.htaccess文件中提到的http://codeigniter.com/wiki/mod_rewrite但替换RewriteBase /RewriteBase /codeigniter/根据您的路径。
  2. 将此文件放在C:\wamp\www\codeigniter\文件夹中
  3. WAMP->Apache->httpd.conf或手动打开 httpd.conf 文件,C:\wamp\bin\Apache\conf\httpd.conf然后找到该行#LoadModule rewrite_module modules/mod_rewrite.so并从头开始替换哈希(#),使完整的行变为LoadModule rewrite_module modules/mod_rewrite.so. 现在重新启动Apache。
  4. 最后打开文件C:\wamp\www\codeigniter\application\config\config.php$config['index_page'] = "index.php";用这个替换$config['index_page'] = "";

Your URLs should now be clean example http://localhost/codeigniter/blogetc.

您的 URL 现在应该是干净的示例http://localhost/codeigniter/blog等。

In case it didn't work, refer to the official wiki: http://codeigniter.com/wiki/mod_rewrite

如果它不起作用,请参阅官方维基:http: //codeigniter.com/wiki/mod_rewrite

回答by Kongnyu derek

  1. Follow the steps above (ans 1) to get mod_rewrite enabled.

  2. To check if enabled, use the WAMPManager menu like so: wampmanager -> Apache -> Module(Scroll the list and make sure is ticked)

  3. create/edit .htaccess on your root CI folder where index.php located.

    <IfModule mod_rewrite.c>
    
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-f
    
        RewriteCond %{REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php/ [L]
    
    </IfModule>
    

    CodeIgniter URLs

  4. Edit config.phpto $config['index_page'] = '';

  1. 按照上面的步骤 (ans 1) 获取mod_rewrite enabled

  2. 要检查是否启用,请使用 WAMPManager 菜单,如下所示: wampmanager -> Apache -> Module(滚动列表并确保已勾选)

  3. 在 index.php 所在的根 CI 文件夹中创建/编辑 .htaccess。

    <IfModule mod_rewrite.c>
    
        RewriteEngine On
    
        RewriteCond %{REQUEST_FILENAME} !-f
    
        RewriteCond %{REQUEST_FILENAME} !-d
    
        RewriteRule ^(.*)$ index.php/ [L]
    
    </IfModule>
    

    CodeIgniter URL

  4. config.php编辑为$config['index_page'] = '';

回答by Iraklis

create/edit .htaccess on your root CI folder (where index.php is located)

在您的根 CI 文件夹(index.php 所在的位置)上创建/编辑 .htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]
    RewriteRule ^(.*)$ /index.php?/ [L]
</IfModule>

回答by vic

may be .htaccess file in your root(application folder) what deny write. change it to allow from all

可能是根目录(应用程序文件夹)中的 .htaccess 文件,拒绝写入。更改它以允许所有人