CodeIgniter Rewrite URL: remove index.php from url

点点圈 提交于 2020-01-06 20:01:50

问题


My apps url is

http://localhost/myapp/admin/index.php/projects

and I want to rewrite it as

http://localhost/myapp/admin/projects

I followed user guide

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

for this but not work for me.


回答1:


Please follow these steps:

1- If you work on localhost please enable mode_rewrite in php.ini

2- Create a .htaccess file under project folder and paste this (please change 'project' to your project folder name):

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

3- Edit this line at application/config.php:

$config['index_page'] = "";



回答2:


Thank /* ActuallyMAB */: Your code actually works. The above code works on localhost (WAMP Server on windows). If you have placed your codeigniter project in some folder such as your directory structure looks like:

C:\wamp\www\proposal

So, You have to replace

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

to

RewriteRule ^(.*)$ /proposal{or your folder name}/index.php/$1 [L]

if this is not the case with your project {you have put your codeigniter directly into www folder}, then remove the folder name from the above code as it looks like;

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

also do not forget to change

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

to

$config['index_page'] = '';

in your config folder {config.php}

I hope others have also provided the same answer, but since the above code works in my project and i felt to provide some details too.



来源:https://stackoverflow.com/questions/11151477/codeigniter-rewrite-url-remove-index-php-from-url

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