托管时隐藏页面的扩展名
所有,
我有一个关于托管的问题。我有用 php 或 JSP 编写的页面,并托管在服务器上。如果用户输入 http://x.com 在浏览器中,将显示 main.php 或 main.asp 页面。我的问题是有没有办法隐藏扩展名。
谢谢...... ....
All,
I had a question on hosting.I have Pages that are written in php or JSP and is hosted on a server .And if a user enter say http://x.com in the browser, the main.php or main.asp page will be displayed.My question is there a way to hide the extensions..
Thanks...........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
选项 1 mod_rewrite / ISAPI 过滤器重写
对于 Apache 上的 mod_rewrite,只需将 .htaccess 文件添加到您网站的根目录,其中包含以下内容...
以下规则将指导所有这种格式的 URI:
对于
IE,URI 的最后一位被转换为同名的 PHP 文件。
选项 2 目录结构
这是一个文件夹结构来代表您的网站,每个文件夹都有一个 index.php 文件。例如,
在此示例中,访问
将为您提供所需的无扩展名 URI,因为默认情况下会显示 index.php 页面。
我只提到这一点,因为它是针对共享 Windows 主机且无法添加 ISAPI 过滤器的情况的解决方案。
Option 1 mod_rewrite / ISAPI filter to rewrite
For mod_rewrite on Apache, it is as simple as adding a .htaccess file to the root directory of your website with the following content...
The following rule will direct all URIs in this format:
to
IE the last bit of the URI gets transformed into a PHP file of the same name.
Option 2 directory structure
This is where you have a folder structure to represent your website and each folder has an index.php file. For example,
In this example, visiting
gives you the extensionless URI that you are after as the index.php page is shown by default.
I only mention this as it is a solution for a situation where you on shared Windows hosting and cannot add an ISAPI filter.
您需要
mod_rewrite
或其之一IIS 等效项。You want
mod_rewrite
or one of its IIS equivalents.如果您使用的是 apache 服务器,则可以通过在 .htaccess 中重写 url 来实现此目的。请参阅http://roshanbh.com.np/2008 /02/hide-php-url-rewriting-htaccess.html
Provided you are using an apache server, you can do this with url rewriting in .htaccess. See http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html