【问题标题】:display only the domain name instead of the full address path when I enter my webpage进入网页时只显示域名而不是完整的地址路径
【发布时间】:2018-10-21 02:43:33
【问题描述】:

当我进入我的网页时,如何设法只显示域名而不是完整的地址路径?

例如,当我搜索“name.com”时,我希望搜索栏只显示“myname.com”而不是“www.name.com/page.html”。

我的index.php入口:

<?php
    header( 'Location: http://www.xxxxx.com/xxxx.html' ) ;
?>

我有一个对应的 'xxx.html' 文件。

我尝试将以下几行添加到 .htaccess 文件中

RewriteEngine On
RewriteCond %{HTTP_HOST} !^name\.com$ [NC]
RewriteRule .? http://name.com%{REQUEST_URI} [R=301,L]

它成功隐藏了'www'前缀,但是,我也想隐藏'/xxxx.html'部分。 该怎么做?

【问题讨论】:

  • 这个问题是关于首页还是整个网站?
  • 只是主页没问题。我想不通@Ali Sheikhpour

标签: url


【解决方案1】:

您必须在服务器设置中定义默认文档。服务器将搜索并找到默认文档并将其作为http://www.example.com/的主页提供服务

在 Windows 服务器中,您可以使用 IIS 管理器 > 默认文档或直接通过 web.config 文件中的此代码设置默认文档:

<configuration>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>
            <add value="home.html" />
         </files>
      </defaultDocument>
   </system.webServer>
</configuration>

在 linux 服务器中,您应该首先编辑 .htaccess 文件并定义主文件:

DirectoryIndex home.php

然后要从地址栏中隐藏主文件,您需要 uisng 重写规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /home.php?/$1 [L]

有关 linux 服务器的更多详细信息,请参阅 tihs Q/Ahere 以及 windows here

如果您使用的是共享托管公司并且可以访问控制面板,您通常可以在网站部分设置默认文档。

【讨论】:

  • 我尝试将这些行添加到 .htaccess 文件中。但它只隐藏“www”前缀。它现在显示“xxxxx.com/xxx.html”。但是,我也试图隐藏实际的 .html 路径,让搜索栏只显示 'xxxxx.com' 。
  • RewriteEngine On RewriteCond %{HTTP_HOST} !^xxxxx\.com$ [NC] RewriteRule .? xxxxx.com%{REQUEST_URI} [R=301,L] ,这些行被添加到 .htaccess 文件中。
猜你喜欢
  • 2017-01-03
  • 1970-01-01
  • 2020-04-04
  • 1970-01-01
  • 2018-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-01
相关资源
最近更新 更多