在我的网站上 ,我有一个主页HTML文件。 然后,当我单击导航栏中的某个内容(例如,名册)时,URL更改为http://www.nextgengaming.org/Roster/roster.html
。 我该如何阻止呢? 我不太担心扩展名,因为以后可以删除它。 这是构建网站时使用的文件/文件夹设置(请注意,在“ Roster”的html文件中没有任何内容,因为我现在专注于url):
Website
∟ Home
∟ CSS
HEADER (social icon images)
home_files (for my image slider)
IMG (the rest of my images)
home.html
home.js
∟ Roster
∟ roster.html
我将用几乎相同的内容填充名册。 在我的导航中,我有
<li><a href="../Roster/roster.html">Roster</a></li>
因此该URL是(如前所述) http://www.nextgengaming.org/Roster/roster.html
,并且想要将其更改为
http://www.nextgengaming.org/Roster
要么
http://www.nextgengaming.org/roster.html
如果您需要更多信息,请发表评论。 另外,我不确定这是否是发布的正确位置,但我会把握机会。
只需使用默认扩展名(通常是index.html
),然后将URL更改为: http://www.nextgengaming.org/Home
: http://www.nextgengaming.org/Home
和http://www.nextgengaming.org/Roster
结构为:
Website
∟ Home
∟ CSS
HEADER (social icon images)
home_files (for my image slider)
IMG (the rest of my images)
index.html
home.js
∟ Roster
∟ index.html
如果您不喜欢这样重命名文件,则更高级的方法是使用URL重写(例如,使用.htaccess)。
网址更改为http://www.nextgengaming.org/Roster/roster.html如何停止此操作?
建议的方法是通过添加来编辑VirtualHost或.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [L]
请注意,必须启用rewrite
模块( sudo a2enmod rewrite
)。 说到DirectoryIndex
( 这里的文档 ),它搜索
index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml
并且如果不存在任何资源并且设置了Indexes
选项,则服务器将生成其自己的目录列表。 Indexes
可能会造成安全威胁(暴露所有文件),因此请使用
Options -Indexes
避免这种情况。 如果遵循指示,
http://www.nextgengaming.org/Roster/roster.html
将被重写为
http://www.nextgengaming.org/Roster/roster
为了避免使用Roster/roster
,而仅将roster
放在您的DocumentRoot
可能将其roster.html
home.html
下一个位置。