WAMP Server Your Projects urls are invalid & do n't work
Your HOSTS file is basically empty as a #
is a comment.
You have to add a reference to each VHOST into your HOSTS file like this so that the browser can find your development domains
Hosts file
127.0.0.1 localhost
::1 localhost
127.0.0.1 phptest
::1 phptest
Now you must restart the DNS Cache like this, from a command prompt that you have started "As an Administrator" or just reboot the PC
>net stop dnscache
When that has completed do
>net start dnscache
Or there is a menu item on WAMPServers menus
[Right Click] wampmanager-> Tools -> Restart DNS
WAMP Server can not direct to the home page
Perhaps I'm oversimplifying, but the root is just localhost and a link specified as href="/"
will always take you there. To link to the localhost/test directory, which is not your root directory it's href="/test"
wampserver -- Links are broken on localhost
By removing the /
you changed it to relative paths.
So you must now think about your path structure.
For example, if the project was placed in a folder, so the root is: http://localhost/mycms/
then you go to ./mycms/cats
the relative path to your CSS would be translated to: ./mycms/cats/css/styles.css
which would break it.
You should look into using absolute paths to assets. For example:
<link rel="stylesheet" href="//localhost/mycms/css/styles.css"/>
This can be achieved by defining or detecting the current URL path from $_SERVER
variables and prepending your hostname.
So something like which stores in a constant which you can then use throughout your code which will result in the correct absolute path to the webroot:
<?php
define('SITE_URL', rtrim(sprintf(
'%s://%s/%s',
isset($_SERVER['HTTPS']) || $_SERVER["SERVER_PORT"] == "443" ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
trim(dirname($_SERVER['SCRIPT_NAME']), '/')
), '/'));
echo SITE_URL;
Then just echo that in your templates.
<link rel="stylesheet" href="<?= SITE_URL ?>/css/styles.css"/>
Related Topics
What Is the Default Username and Password of Phpmyadmin
How to Store Values from Foreach Loop into an Array
Using JavaScript History.Back() Fails in Safari .. How to Make It Cross-Browser
How to Update Field to Add Value to Existing Value
Regex for Only Allowing Letters, Numbers, Space, Commas, Periods
How to Remove a Directory That Is Not Empty
How to Fetch Record of Many Ids on Single Query
How to Pass Variable Between Two Web Pages With PHP Without Using Session
Getting Error in Console:Failed to Load Resource: Net::Err_Connection_Reset
How to Get All Month Record Count in Laravel
Laravel Print Array in Blade PHP
Telegram Bots - How to Create Reply Menus With Icons Like Mypokerbot
How to Prevent a User from Directly Accessing My HTML Page by Writing Url
Strip Null Values of Json Object