javascript 如何在地址栏中隐藏我的页面名称和扩展名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11445522/
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
How can I hide my page name and extension in the address bar?
提问by fathima
How can I hide my page name and extension in the address bar?
如何在地址栏中隐藏我的页面名称和扩展名?
For example when I click on my "Home" link, it would take me to:
例如,当我点击我的“主页”链接时,它会带我到:
www.mysite.com/index.html
www.mysite.com/index.html
but instead I'd like it show in the address bar without the page name and extension, like this:
但相反,我希望它显示在没有页面名称和扩展名的地址栏中,如下所示:
www.mysite.com/
www.mysite.com/
采纳答案by arttronics
How are you writing your "Home" link?
您如何编写“主页”链接?
Having said that, don't include the /index.html
portion in your anchor tag.
话虽如此,请不要/index.html
在您的锚标签中包含该部分。
Also, if you wanted to show the main site URL www.mysite.com
for every local link in your site no matter the webpage your at (photo gallery, about us, etc.), wrap your whole website in a iframethat's the entire space of the viewport which will prevent the Address Barfrom changing.
此外,如果您想显示www.mysite.com
您站点中每个本地链接的主站点 URL ,无论您所在的网页(照片库、关于我们等)是什么,请将您的整个网站包装在一个iframe 中,该iframe是整个视口空间将阻止地址栏更改。
Reference:jsFiddle or is it???
The above jsFiddle site shows this simple iframe method described. Notice that the Address Bar is always at the same place since the iframe is receiving all the navigation interaction.
上面的 jsFiddle 站点展示了这个简单的 iframe 方法。请注意,地址栏始终位于同一位置,因为 iframe 正在接收所有导航交互。
View that jsFiddle without the /show/
as seen in the Address Barto access the Edit Page.
查看该 jsFiddle 没有/show/
在地址栏中看到的那样访问编辑页面。
回答by Tschallacka
this should work.
这应该有效。
Put this in a file called .htaccess and put it in your root directory. Only works on a apache webserver though and not locally.
把它放在一个名为 .htaccess 的文件中,并将它放在你的根目录中。仅适用于 apache 网络服务器,而不适用于本地。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule .* RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html
.html
回答by Divyesh Kanzariya
Create an .htaccess
file in your website's root directory with the following content:
.htaccess
在您网站的根目录中创建一个文件,内容如下:
www.mysite.com/index.html
When you've added the above file you can access the following url:
添加上述文件后,您可以访问以下网址:
www.example.com/contactus
by using this url:
通过使用这个网址:
window.location.href = 'WHAT LOCATION YOU WANT';
回答by micnic
You can try:
你可以试试:
##代码##But this will reload the page. You should find the solution on the server side.
但这将重新加载页面。您应该在服务器端找到解决方案。