Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url 从网页名称中删除扩展html_Url_Web - Fatal编程技术网

Url 从网页名称中删除扩展html

Url 从网页名称中删除扩展html,url,web,Url,Web,我的网站的第一个页面叫做index.html 当我在地址栏中输入: http://websit/index.html 但是 现在,我的老板问我,他只想要这个名字http://websit/index 如何实现这一点?标准的web服务器行为是将“index.html”文件作为路径调用的根文件加载。意思是: http://websit/ 与此相同: http://websit/index.html 这样做(如下)只会导致更多问题,因为索引似乎是路径而不是文件: http://websit/ind

我的网站的第一个页面叫做index.html 当我在地址栏中输入:
http://websit/index.html

但是

现在,我的老板问我,他只想要这个名字
http://websit/index


如何实现这一点?

标准的web服务器行为是将“index.html”文件作为路径调用的根文件加载。意思是:

http://websit/
与此相同:

http://websit/index.html
这样做(如下)只会导致更多问题,因为索引似乎是路径而不是文件:

http://websit/index

因此,如果你想清理东西,只需参考
http://websit/index.html
just
http://websit/

如果您使用的是Apache,则需要检查Mod Rewrite是否已启用,然后阅读有关.htaccess和Mod Rewrite的文章

解决方案: 在根目录(index.html所在的位置)上创建一个名为.htaccess的文件。然后,复制此代码(将其粘贴到.htaccess文件中),并使用不带.html的website/index再次测试它

#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]

可能重复: