我的网站第一页名为index.html
当我放入地址栏时:
http://websit/index.html
它有效
但
现在我的老板问我他只想要这个名字http://websit/index
我该怎么做?
答案 0 :(得分:0)
标准Web服务器行为只是将“index.html”文件加载为路径调用的根文件。这意味着:
http://websit/
与此相同:
http://websit/index.html
执行此类操作(如下所示)只会导致更多问题,因为索引似乎是路径而不是文件:
http://websit/index
所以如果你想要清理的话,只需http://websit/index.html
http://websit/
{/ 1>}即可。
答案 1 :(得分:0)
如果你正在使用Apache,那么你需要检查是否启用了Mod Rewrite,然后阅读有关.htaccess和mod rewrite的文章。
解决方案: 在根目录(index.html)所在的位置创建一个名为.htaccess的文件。然后,复制此代码(将其粘贴到.htaccess文件中)并使用不带.html的网站/索引再次测试
#comments
RewriteEngine On
#base directory for this file, if its root, then its one /, if its test then its /test
RewriteBase /
#if the URL for the resource that requested is not exist as file
RewriteCond %{SCRIPT_FILENAME} !-f
#if the URL for the resource not exist as directory
RewriteCond %{SCRIPT_FILENAME} !-d
#then it anything types after the website/() redirect it to ().html
RewriteRule ^(.*)$ $1.html [NC,L]
#the ^ and $ used for matching whole string (from beginning to end)
#the () used for grouping matching strings
#the . used for matching any character
#the $1 represents the match group, for our example we used one () then its $1
[1] http://httpd.apache.org/docs/current/howto/htaccess.html