从 URL 中删除 index.php - Codeigniter 2
我在从 Codeigniter 中的 URL 中删除 index.php 时遇到问题。我用 Codeigniter 1.7 制作了一些网站,而我使用的 .htaccess 代码在 2 中不起作用。
我尝试过使用
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
,并且
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>
在没有 RewriteBase / 的情况下也尝试过。
我更改了 $config['uri_protocol' ] 到 REQUEST_URI 和 QUERY_STRING,什么也没有。
我已经设置了 $config['index_page'] = "";
文件结构是192.168.0.130/(site)/,所以它一定是回到服务器的根目录,找不到index.php文件。
我制作的所有控制器都可以通过输入 192.168.0.130/(site)/index.php/testcontroller 来访问,
谢谢。
如果之前有人问过这个问题,我深表歉意 - 我已经查看并尝试了我能看到的内容。
编辑:
我还应该补充一点,我将默认文件夹更改为
应用程序
CI-2.0
index.php
并将 index.php 中的路径更改为正确的。
I am having trouble removing index.php from my URLs in Codeigniter. I've made a few websites with Codeigniter 1.7 and the .htaccess code I used doesn't work in 2.
I have tried using
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
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
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
and
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>
I've also tried it without RewriteBase / in.
I have changed the $config['uri_protocol'] to REQUEST_URI and QUERY_STRING and nothing.
I have set $config['index_page'] = "";
The file structure is 192.168.0.130/(site)/ so it must be going back to the root of the server and can't find the index.php file.
All of the controllers I have made can be reached by putting 192.168.0.130/(site)/index.php/testcontroller
Thank you.
Apologies if this has been asked before - I have looked and tried what I could see.
Edit:
I should also add that I changed the default folders to be
application
CI-2.0
index.php
and changed the paths in index.php to be correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
尝试您发布的第一个代码块,但尝试使用 /(site)/index.php 代替 /index.php (obv 将 (site) 替换为您的站点文件夹的名称)。
Try the first code block you posted, but instead of /index.php try using /(site)/index.php (obv replacing (site) with whatever your site folder is named).
这对我有用:
这是我的 htaccess 文件:
来源:
http://taggedzi.com/articles/display/codeigniter -2-htaccess-and-friend-urls
This worked for me:
This is my htaccess file:
Source:
http://taggedzi.com/articles/display/codeigniter-2-htaccess-and-friendly-urls
我为此呆了两天..尝试了一切可能的方法。我刚刚发现您需要以下内容:
类型:
并将AllowOverride None更改为AllowOverride All - 这将允许访问您的.htaccess文件
并且还可以在Apache上启用mod重写:
希望这会有所帮助,
马里奥
I was on this for 2 days.. Tried everything possible. I've just came out that you need the following:
TYPE:
And change AllowOverride None to AllowOverride All - This will give access to your .htaccess files
And also enable mod rewrite on Apache:
Hope this helps,
Mário
仅在根文件夹中需要这么多,将其添加到 .htaccess
This much is only required in root folder add this to .htaccess
遵循其他人以及此 CodeIgnitor URL 文档 的所有说明后,不要忘记重新启动服务器。我只是忘记这样做并继续尝试所有其他解决方案。
After following all instructions from other people and from this CodeIgnitor URL documnetation, don't forget to restart the server. I simply forgot to do that and kept trying all other solutions.
您只需在 .htacess 中添加以下代码即可。
You just need to add below code in .htacess.
1)在根文件夹中创建 .htaccess 文件
2)在应用程序文件夹中编辑 application/config/config.php 文件
我希望它对您有用
1) Create .htaccess file in your root folder
2) Edit application/config/config.php file in Application folder
i hope it will work for you