Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative path not working when website is deployed

I have a website that has a relative path to a stylesheet that looks like this "/stylesheets/main.css". Now this works fine when I run the site in Visual Studio. But when I deploy the site to our Windows Server 2003 the path stops working. If I go back into code and change the path from "/stylesheets/main.css" to "stylesheets/main.css", the site works fine on the server. I have another website on a different server that uses the same path style ("/stylesheets/main.css") and stylesheet and works with no problems. I really don't want to change all the paths, and am not even sure if this is a problem with the code or the server. Any help or ideas would be great. Thanks.

like image 677
user229133 Avatar asked Dec 07 '22 04:12

user229133


2 Answers

Is the site deployed to the domain's root? If the site is at

http://example.com/somefolder/

then the path /stylesheet/main.css will be interpreted as

http://example.com/stylesheet/main.css

rather than

http://example.com/somefolder/stylesheet/main.css

As @Kit indicated, you can work around this by resolving the path to your application's folder. I have often done this in ASP.NET as follows:

<link rel="stylesheet" type="text/xss" href="<%= ResolveUrl("~/stylesheet/main.css") %>"/>

If that's not the problem, you're going to have to give a bit more detail.

like image 100
harpo Avatar answered May 12 '23 08:05

harpo


In ASP.NET, many times you will need to use a tilde (~) to get the application's root directory, so your paths would look like ~/stylesheets/main.css

When you specify a path that starts with / you are indicating the server root so if you have you site in a virtual directory, it will not be taken into account, but if the site is hosted as the default site, the path will qualify:

Example: server named foo.net with site hosted in a virtual directory named app /stylesheet will translate to foo.net/stylesheet not foo.net/app/stylesheet

like image 35
Kit Roed Avatar answered May 12 '23 08:05

Kit Roed