Stylesheet not being displayed in WAMP project

流过昼夜 提交于 2020-01-06 20:35:30

问题


I have been following this guide to setting up a WAMP project using Virtual Hosts.

When I browse to "localhost/website", it loads my homepage but without the stylesheet or any images. Here is the file structure:

  • wamp/www/website/index.php
  • wamp/www/website/images/image.png
  • wamp/www/website/styles/style.css

httpd-vhosts.conf:

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www/website"
    ServerName website
    <Directory "c:/wamp/www/website">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

---

Also, as an aside, I can't get the "My Virtual Hosts" section to appear in the wampmanager menu; I have added the parameter from the guide and restarted wampserver but I still don't see it. Here is my [Menu.Left] section in wampmanager.tpl:

[Menu.Left]
;WAMPMENULEFTSTART
Type: separator; Caption: "Powered by Alter Way"
Type: item; Caption: "${w_localhost}"; Action: run; FileName: "${c_navigator}"; Parameters: "http://localhost/"; Glyph: 5
;WAMPPROJECTSUBMENU
;WAMPVHOSTSUBMENU

回答1:


If the path to your stylesheet in your HTML is styles/style.css or /styles/style.css, then it will be pointing to wamp/www/styles/style.css rather than wamp/www/website/styles/style.css.

Since you are setting up a virtualhost, I assume you meant to use it. You will want to point your browser to website/, rather than localhost/website/. If you point your browser to localhost/website/ then you are actually using the first virtualhost entry rather than the second.

Once you point your browser to the correct host, the css should work properly since it will then point to wamp/www/website/styles/style.css.




回答2:


I assume you have created the virtual hosts definitions in the \wamp\bin\apache\apachex.y.z\conf\extra\httpd-vhost.conf file?

Have you also uncommented the line in httpd.conf that includes that file into the configuration?

edit httpd.conf, somewhere near the bottom of the file there is this line

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Uncomment that line by removing the # symbol.

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Also you need to add this to your HOSTS file as well

Add this to \windows\system32\drivers\etc\hosts

127.0.0.1 localhost website
::1 localhost website



回答3:


If you already have WAMP working, and your website loads fine on the localhost ie: The PC running WAMP, but when you load the website/webpage from another PC, the site loads, but without style-sheets and looks all plain and ugly etc, then:

THE ONLY THING YOU HAVE TO DO IS:

In WordPress Admin -> Click Settings -> Click General -> and replace the "WordPress Address URL" and "Site Address URL" from the default setting of:

"http:// localhost/yourSiteName" to a URL that uses the IP Address of the WAMP PC

Replace the localhost with the IP Address OF the localhost so then URLs must now look like this:

"http:// 192.168.1.27/yourSiteName" That's if the IP Address of your WAMP PC = 192.168.1.27

If you don't know the IP Address of your WAMP PC, open a command prompt on the WAMP PC by clicking the Start Button on the Windows Task-Bar and then select "Run" from the Start Menu (or push the Windows Button (between CTRL and ALT on the left side of the keyboard) TOGETHER with the letter "R" (in that order)) you will see a Run Dialogue box appear, then clear the text area if it has anything already there, then type "cmd" and click OK.

You will see a Black screen pops-up that lets you type stuff, if it has stuff on the screen already, don't worry it is supposed to be there, just type "ipconfig" and then hit the Enter button on your keyboard, then look in the results that return on the screen for something to likes of:

IPv4 Address................192.168.1.27

That IS your IP Address ie: 192.168.1.27

Now replace the "localhost" part of the WordPress Site URLs in WordPress General Settings (discussed above) and click save.

Now it works - BOOM!!


Extra Tip : In the WordPress Admin site, Click Settings from the menu, Click Permalinks from the Settings Menu and then change the default setting from "Plain" to "Post Name". This will make all your URLs and web page URLs look the best.

eg:

Plain = "http:// 192.168.1.42/yourSiteName/?p=123"

Alternatively, select Post Name:

Post Name = http:// 192.168.1.42/yourSiteName/awesome/people.php

Which in my opinion is much better and nicer to share with friends etc...



来源:https://stackoverflow.com/questions/25248683/stylesheet-not-being-displayed-in-wamp-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!