0

How can I manage to display only the domain name instead of the full address path when I enter my webpage?

For example, when I search 'name.com', I want the search bar shows only 'myname.com' instead of 'www.name.com/page.html'.

my index.php entrance:

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

and I have a corresponding 'xxx.html' file.

I've tried adding the following lines to .htaccess file

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

.

it successfully hiding 'www' prefix, however, I also want to hide '/xxxx.html' part. How to do that?

Jim
  • 1
  • 2

1 Answers1

0

You have to define the default document in server settings. Server will serach and find the default document and servs it as hompage of http://www.example.com/

In a windows server you can set default document using IIS manager > Default documents or directly by this code in web.config file :

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

in a linux server , you should first edit .htaccess file and define the home file:

DirectoryIndex home.php

and then to hide the home file from address bar you need uisng rewrite rule :

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

for more details in linux server please refer to tihs Q/A and here and for windows here.

If you are using a shared hosting company and have access to control panel, you can set default documents usually in in websites section.

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • I've tried adding these lines to .htaccess file. but it only hides 'www' prefix. It now displays 'xxxxx.com/xxx.html'. However, I am trying to hide the actual .html path as well, and let search bar only displays 'xxxxx.com' . – Jim Oct 21 '18 at 03:29
  • RewriteEngine On RewriteCond %{HTTP_HOST} !^xxxxx\.com$ [NC] RewriteRule .? http://xxxxx.com%{REQUEST_URI} [R=301,L] , these are lines being added to .htaccess file. – Jim Oct 21 '18 at 03:29