使用的.htaccess,从来没有表现出的index.php [英] Using .htaccess, never show index.php

查看:152
本文介绍了使用的.htaccess,从来没有表现出的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能永远​​不会显示的index.php?例如,所有的请求到
site.com/index.php/controller 重定向在浏览器地址栏
  site.com/controller

How can I never show index.php? For example, all requests to
site.com/index.php/controller are redirected in the browser address bar to
site.com/controller?

我目前的.htaccess删除的index.php,但是当用户直接类型的 site.com/index.php/controller 他们仍然显示在地址栏中的地址,而不是网站.COM /控制器

My current .htaccess removes index.php but when a user directly types site.com/index.php/controller they are still shown that address in the address bar as opposed to site.com/controller

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$的index.php?/ $ 1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

注:在燃烧,我已签了很多解决重定向的index.php的.htaccess线程,但我还没有找到一个永远不会显示的index.php。这里有几个...
<一href="http://stackoverflow.com/questions/2865412/htaccess-to-not-show-index-php-in-sub-directory">Not显示的index.php在子目录
<一href="http://stackoverflow.com/questions/2192136/how-to-remove-index-php-from-url-in-$c$cigniter">remove index.php文件在codeigniter

NOTE: Before flaming, I have checked lots of .htaccess threads that solve redirecting index.php but I haven't found one to never show index.php. Here are a few...
Not Show index.php in subdirectory
remove index.php in codeigniter

推荐答案

对于任何人寻找一个更通用的解决方案:

For anyone looking for a more generalized solution:

Options +FollowSymLinks -MultiViews

#Disallow listing contents of subfolders
Options All -Indexes

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If index or index.php requested, strip and redirect
RewriteCond %{THE_REQUEST} index(\\.php)?
RewriteRule ^index(\\.php)?$ http://yourdomain.com/ [R=301,L]

## Part 1
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## Part 2 - handle incoming that lacks extension (except for existing folders)
## To redirect /dir/foo to /dir/foo.php, (skip for admin or user dirs)
RewriteRule ^(admin|user)($|/) - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

这篇关于使用的.htaccess,从来没有表现出的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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