有没有办法在不指定索引页面名称或完整网站 URL 的情况下链接到网站的索引页面?
我有这个:
<a href="index.htm">Home</a>
但是当我点击链接时,我的地址栏显示:
mydomain.com/index.html
我希望它显示:
mydomain.com
我可以在不将完整 URL ( mydomain.com
)放入的情况下执行此操作href
吗?如果是这样,怎么做?
对于未来的观众,我也发现这个问题很有帮助。
你可以这样做:
<a href="/">Home</a>
任何href
前面有斜线的都是相对的根目录。
需要注意的是,在浏览器中从本地硬盘查看网页时,会导致链接失效。
我知道这篇文章很旧并且有答案。但这是我的贡献,它也支持不完全在根目录中的索引
要去
mydomain.com/index.html
without index.html showing in address bar
<a href="/">Home</a>
this will always point to mydomain.com no matter where the directory your file was saved to.
to point to the index in a directory use this:
<a href="./">Home</a>
this will point to mydomain.com/subdir for mydomain.com/subdir/index.html while the accepted answer will always point to mydomain.com (and this is not always the desired action)
Create a ".htaccess" file and upload to your host public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.yourwebsite.com.ph/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>