我如何从URL中移除的index.php? [英] How do I remove index.php from the URL?

查看:154
本文介绍了我如何从URL中移除的index.php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除URL与.htaccess中的index.php文件,我已经来了一半的路,我无法弄清楚什么是错的。

I'm trying to remove the index.php from the url with .htaccess and I have come half way and I can't figure out what is wrong.

我/使用以下设置/系统:

I have/using the following settings/system:

  • codeigniter 2.1.4
  • 的Ubuntu 12.04
  • $配置['BASE_URL'] ='的http://本地主机/ present';
  • 的Apache2
  • 在PHP5
  • Codeigniter 2.1.4
  • Ubuntu 12.04
  • $config['base_url'] = 'http://localhost/present';
  • apache2
  • php5

当我尝试以下网址:

的http://本地主机/ present /测试它显示的页面。到目前为止,一切都很好。

http://localhost/present/test it displays the page. So far so good.

的http://localhost/$p$psent/index.php/test 这也显示页面,所以我得到重复的网页。这是我的问题。

http://localhost/present/index.php/test it also displays the page so I get duplicate pages. And that is my problem.

我使用的是在同一个文件夹中的index.php下面的.htaccess。

I'm using the following .htaccess in the same folder as index.php.

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

能否一些友好的灵魂告诉我什么是错的?它是mod_rewrite的或者一些服务器/ PHP的设置是错误的?

Can some friendly soul tell me what is wrong? Is it the mod_rewrite or maybe some server/php settings that are wrong?

推荐答案

这应该工作。

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !no-redir
RewriteRule ^/?index.php/(.*)$ $1 [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule .* index.php/$0?no-redir [L]

这篇关于我如何从URL中移除的index.php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆