Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of ending forward slash for Apache virtual-hosts

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?

like image 802
Francisc Avatar asked Dec 13 '25 12:12

Francisc


1 Answers

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)

like image 155
pangon Avatar answered Dec 15 '25 21:12

pangon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!