Html 如何隐藏我网站的完整网址?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19606433/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:46:00  来源:igfitidea点击:

How can i hide the full url of my website?

html

提问by buri

When i upload my website files to my server and goto my website, i see the index.html at the url bar of the browser. How can i hide this?

当我将我的网站文件上传到我的服务器并转到我的网站时,我在浏览器的 url 栏中看到 index.html。我怎样才能隐藏这个?

http://bakpinar.com/about/about-us.html

http://bakpinar.com/about/about-us.html

I would like it to look like in this example;

我希望它在这个例子中看起来像;

http://www.royaltyline.com

http://www.royaltyline.com

as you can see, you only see the website address in the url bar of the browser. And when you click to another page, it doesnt show the .php, .asp or .html extension, just shows the folder name.

如您所见,您只能在浏览器的 url 栏中看到网站地址。当你点击另一个页面时,它不会显示 .php、.asp 或 .html 扩展名,只显示文件夹名称。

tia

蒂亚

burak

布拉克

回答by Snowburnt

To hide the extension shown in the address bar, you have two options.

要隐藏地址栏中显示的扩展程序,您有两个选择。

  1. If you control the server, you can define rules that rewrite the URL based on the one the user is trying to get to. In PHP you can use the .htaccess file to define mod_rewrite rules. For similar features to .htaccess you can install the application request routing module in IIS 7 and above. In IIS (Windows) you can set up default pages that come up when users go to particular sites.
  2. You can also make that all of your pages are accessed through the same page using AJAX, or put all the content on the same page and hide it using CSS and display it with CSS and/or JS.
  1. 如果您控制服务器,则可以定义根据用户尝试访问的 URL 重写 URL 的规则。在 PHP 中,您可以使用 .htaccess 文件来定义 mod_rewrite 规则。对于与 .htaccess 类似的功能,您可以在 IIS 7 及更高版本中安装应用程序请求路由模块。在 IIS (Windows) 中,您可以设置用户访问特定站点时出现的默认页面。
  2. 您还可以使用 AJAX 通过同一页面访问您的所有页面,或者将所有内容放在同一页面上并使用 CSS 隐藏它并使用 CSS 和/或 JS 显示它。

This is a very high level answer, because the specifics vary greatly from situation to situation.

这是一个非常高级的答案,因为具体情况因情况而异。

回答by Jakub Matczak

It's not actually a folder name. It's rewritten URL.

它实际上不是文件夹名称。它是重写的 URL。

To do such things you should redirect all requests to one file (index.php for example), then parse URL and basing on its parts, show particular file.

要执行这些操作,您应该将所有请求重定向到一个文件(例如 index.php),然后解析 URL 并根据其部分显示特定文件。

To redirect everything to index.php, use mod_rewrite module of Apache + .htaccess file.

要将所有内容重定向到 index.php,请使用 Apache + .htaccess 文件的 mod_rewrite 模块。

To choose specific file you can implement one of several approaches. It's usually called routing in design patterns.

要选择特定文件,您可以实施多种方法之一。它通常在设计模式中称为路由。

Completely other approach would be to use AJAX for reloading content. But it's not the way it was made on the website you gave as example.

完全不同的方法是使用 AJAX 重新加载内容。但这不是在您举例的网站上制作的方式。

In general there is a lot of information about routing urls in PHP on the web. Just do some research.

一般来说,网上有很多关于在 PHP 中路由 url 的信息。只是做一些研究。

回答by Sebastyne

An easy way to do this, in case someone is still looking, is to use a full-screen iFrame. No matter where on the page your users are, they will always only see the main url. This used to be very popular back in the day, but it was a terrible practise in terms of usability.

如果有人还在寻找,一个简单的方法是使用全屏 iFrame。无论您的用户在页面上的哪个位置,他们始终只能看到主 URL。这在当时非常流行,但就可用性而言,这是一种糟糕的做法。

<html><head>the stuff</head><body>
<iframe src="http://bakpinar.com/about/about-us.html" width=100% height=100%></iframe></body></html>

Write that into the index.html file at http://www.royaltyline.com

将其写入http://www.royaltyline.com 上的 index.html 文件

回答by Code Monkey

You are effectively looking to rewrite URLs. If your web server is Apache you will be able to use the rewriting module (mod_rewrite) to direct requests to http://bakpinar.com/about/to http://bakpinar.com/about/about-us.html

您正在有效地寻求重写 URL。如果您的 Web 服务器是 Apache,您将能够使用重写模块 (mod_rewrite) 将请求定向到http://bakpinar.com/about/http://bakpinar.com/about/about-us.html

If you are not running Apache, most web servers will serve index.html as the default page when requesting a directory, so renaming

如果您没有运行 Apache,大多数 Web 服务器将在请求目录时提供 index.html 作为默认页面,因此重命名

about-us.html

to

index.html

and changing incoming links to

并将传入链接更改为

/about/about-us.html 

to simply

简单地

/about/

Will give you the same results.

会给你同样的结果。

回答by Manjeet Kumar Nai

Yes, you can do by javascript.

是的,您可以通过 javascript 来完成。

<script>
       window.history.replaceState('','','/');
</script>