隐藏 URL 的 index.php(或 index.html)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1288678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide index.php (or index.html) of an URL
提问by Philippe Carriere
When I type the address of my site in a browser (mysite.com), it redirects to mysite.com/index.php. Why not to index.html ? Because I changed it in the conf file in Apache 2.2 .
当我在浏览器 (mysite.com) 中输入我的网站地址时,它会重定向到 mysite.com/index.php。为什么不 index.html ?因为我在 Apache 2.2 的 conf 文件中更改了它。
- Now I would like to hide the last "index.php" part. How do I do that ?
- Would it be different it was index.html than index.php ?
- 现在我想隐藏最后一个“index.php”部分。我怎么做 ?
- index.html 和 index.php 会有所不同吗?
Wouldn't be ugly if by looking for google, you would end up on www.google.com/index.html ? ... it's just for esthetics but god is it important to certain people.
如果通过寻找谷歌,你会在 www.google.com/index.html 上结束会不会很丑?......这只是为了美学,但上帝对某些人来说很重要。
回答by Thinker
I don't know why you need to use mod_rewrite. On my site I did nothing to hide index.php, I just don't point it anywhere in code, so instead of www.example.com/index.php?task=forum I just write www.example.com/?task=forum. It works on standard apache config.
我不知道你为什么需要使用 mod_rewrite。在我的网站上,我没有做任何隐藏 index.php 的事情,我只是没有在代码中的任何地方指出它,所以我只写 www.example.com/?task 而不是 www.example.com/index.php?task=forum =论坛。它适用于标准的 apache 配置。
回答by Pablo Santa Cruz
If it's redirecting, (by sending a new Location on HTTP header, for example) then there's nothing you can do but changing the code that's doing the redirect.
如果它正在重定向(例如,通过在 HTTP 标头上发送一个新位置),那么除了更改执行重定向的代码外,您无能为力。
On the other hand, if your WebServer is Apache, there is a configuration directive that might help:
另一方面,如果您的 WebServer 是 Apache,则有一个配置指令可能会有所帮助:
DirectoryIndex
目录索引
When you set that to: index.phpor index.html, then your web server will automatically redirect to those internal files without changing the URL when you hit the directory on your server where the DirectoryIndexdirective is setup.
当您将其设置为:index.php或index.html 时,当您点击服务器上设置DirectoryIndex指令的目录时,您的 Web 服务器将自动重定向到这些内部文件,而不会更改 URL 。
I guess you'll get better answers if you post this on SERVERFAULT.
我想如果你在SERVERFAULT上发布这个,你会得到更好的答案。
Good luck.
祝你好运。
回答by ADC
This seemed to work in my environment (would NOT display index.php):
这似乎在我的环境中有效(不会显示 index.php):
<form action="." method="POST">
E-mail: <input type='password' size='50' name='email' />
<input type='submit' value='Login' />
</form>
回答by Kris Erickson
You can easily do this with URL mapping in either the http.conf file or individual .htaccess files in your application directories. Turn on mod rewrite. Hereis a simple tutorial.
您可以使用 http.conf 文件或应用程序目录中的单个 .htaccess 文件中的 URL 映射轻松完成此操作。打开mod 重写。 这是一个简单的教程。

