how to configure codeigniter mod_rewrite on wamp?

丶灬走出姿态 提交于 2019-12-08 01:14:34

问题


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

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

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


回答1:


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

  1. Create a .htaccess file as mentioned in http://codeigniter.com/wiki/mod_rewrite but 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.conf or manually from C:\wamp\bin\Apache\conf\httpd.conf then locate the line #LoadModule rewrite_module modules/mod_rewrite.so and 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.php and replace $config['index_page'] = "index.php"; with this $config['index_page'] = "";

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

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




回答2:


  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/$1 [L]
    
    </IfModule>
    

    CodeIgniter URLs

  4. Edit config.php to $config['index_page'] = '';




回答3:


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

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



回答4:


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



来源:https://stackoverflow.com/questions/1014547/how-to-configure-codeigniter-mod-rewrite-on-wamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!