3

I've set-up Apache on Windows 7 to have a few Virtual Hosts for local development purposes.
The httpd-vhosts.conf file has this format for all virtual hosts:

<VirtualHost *:80>
   ServerName example.dev
   DocumentRoot "C:/Program Files (x86)/Apache2.2/htdocs/example.dev/"  # <--removing the forwardslash here doesn't fix this
</VirtualHost>

The Windows hosts file has this for each:

127.0.0.1       example.dev

Now, what bothers me is that each time I type example.dev in the address bar, it gets added an extra trailing forwardslash, becoming example.com/. I get this for all my virtual hosts. Simply accessing localhost does not add the trailing forwardslash. This does not happen: localhost/.
Not a big deal, but it bothers me and I can't find a solution to that.

Any ideas?

Francisc
  • 77,430
  • 63
  • 180
  • 276

1 Answers1

4

The additional slash is not caused or avoidable by your Apache configuration, it's a "feature" of browsers that are composing the HTTP parameters of the browsers created HTTP POST or GET request to the web server.

In order to request the home page of www.example.com the HTTP browser generated code is something similar to:

GET / HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/4.0

and the browser is simply displaying the concatenation of the Host name plus the string after the GET/POST

It could be that some browsers will not display it, but it doesn't change the fact that the HTTP requests is requesting /

The case of localhost is a different policy on browsers, and it's simply an alias (the Host: field of HTTP is not localhost)

pangon
  • 439
  • 5
  • 18
  • You might be right, but I think it can be avoided. I think `localhost` is in the same situation. But taking another example, going to `stackoverflow.com`, does not add a trailing slash. – Francisc Sep 08 '12 at 23:12
  • what browser/os are you using? – pangon Sep 08 '12 at 23:14
  • Chrome latest stable and Windows 7. – Francisc Sep 08 '12 at 23:15
  • Just to check, you get the additional slash if in the DocumentRoot directory there is an index.html page? Not sure at all, but it could be related to the settings of apache directory listing. – pangon Sep 08 '12 at 23:26
  • Usually there's an index.php file. ` DirectoryIndex index.html index.php` – Francisc Sep 08 '12 at 23:29
  • I'm not able to reproduce the additional / :( – pangon Sep 08 '12 at 23:35
  • Many thanks for taking the time to help. It might not be possible, like you say. Firefox, for example, does not show that extra slash. – Francisc Sep 08 '12 at 23:37
  • 1
    Using the chrome developer tools, check in the networking, and read the original HTTP requests. Look if there is something different between cases that are adding the / and cases that don't. Currently in chromium/linux when copying a URL without / and pasting it in a text editor it's displaying the / that's hidden in the address bar, I'm almost sure the display or not (in the hostname with void path case only) is a browser setting and not an Apache setting. Give a look at this question: http://stackoverflow.com/questions/2581411/do-web-browsers-always-send-a-trailing-slash-after-a-domain-name – pangon Sep 08 '12 at 23:40