Jump to content

Hello,

 

I organized my files in different folders to keep it simple. The problem is that it's hard to keep my links (ex: to stylesheet, to other pages) accurate since some of these files (with the links in them) are in sub-folders, so I need to do "../pages/contact.php" for one, "styles/css/main.css" for another, etc.

 

It would be easier if I could just start from root everything, so have "index.php/pages/contact.php" instead of "../pages/contact.php", same thing for images and javascript.

 

I think that you can put a slash (/) before your links to return to the root of the website, however this is not working in local.
Is there any alternative to that that works in local?

 

I remember watching a Chris Coyier video where he "simulated" a domain name, so even if he was in local he still had a (fictionnal) domain showing up in the adress bar, and he was able to use the slashes (/) to return to root, even if he was still in local. It was a premium video and I'm not a member anymore, and I couldn't find what he was using.

 

Are there any programs (on Windows) to do that?

 

Thanks a lot !

Link to comment
https://linustechtips.com/topic/177546-links-to-root-in-local-htmlphp/
Share on other sites

Link to post
Share on other sites

I remember watching a Chris Coyier video where he "simulated" a domain name, so even if he was in local he still had a (fictionnal) domain showing up in the adress bar, and he was able to use the slashes (/) to return to root, even if he was still in local. It was a premium video and I'm not a member anymore, and I couldn't find what he was using.

Well, we do this with our chat server at my workplace. 

It required that I have my DNS server redirect to <some IP> when it <some url> was typed into the address bar. I'm not sure how to do it without a DNS server though. 

† Christian Member †

For my pertinent links to guides, reviews, and anything similar, go here, and look under the spoiler labeled such. A brief history of Unix and it's relation to OS X by Builder.

 

 

Link to post
Share on other sites

 

 

I vouch for WAMP, a simple and effective solution for a local host.

 

Thanks, I've installed it. Do I need to create an alias now to use the "/" to get to the root? Because at the moment it still opens my index file in "localhost" (in the adress bar)

Link to post
Share on other sites

@Drown

Okay, you seem to have issues with file structure if this is actually a problem. But I will give you a fix anyway.

Changing the default path of the links is easy and is pure HTML.

Just use the HTML <base> tag to choose the default URL. Though by default this is the root of your website so you shouldn't be having a problem. I hate linking to w3schools, since they get a lot of stuff wrong, but it's a decent reference:

http://www.w3schools.com/tags/tag_base.asp

In PHP, go to php.net and look up the chdir() function. It allows you to specify the base directory for stuff such as includes.

Link to post
Share on other sites

Okay, you seem to have issues with file structure if this is actually a problem. But I will give you a fix anyway.

 

Do you have a file structure to propose? It's only a problem with a few elements, but even if it's a minority it would be easier to have access to the root in my links, just to simplify everything. :)

 

 

Just use the HTML <base> tag to choose the default URL.

 

Would it work even if I'm in local? There's no domain name, it's just localhost at the moment

Link to post
Share on other sites

Do you have a file structure to propose? It's only a problem with a few elements, but even if it's a minority it would be easier to have access to the root in my links, just to simplify everything. :)

Probably if I could see everything, but It's late here so I'm going to say no.

Would it work even if I'm in local? There's no domain name, it's just localhost at the moment

Do you have XAMPP/WAMP installed? If so, stick all your files in that directory so you can access it via http://localhost. Then it will work, just set the href to http://localhost - that is a valid URL.

Even without a server, that might (probably) still work

Link to post
Share on other sites

I think that you can put a slash (/) before your links to return to the root of the website, however this is not working in local.

Is there any alternative to that that works in local?

it should be working for HTML links

for PHP file paths, i think you can't address directly the root of your website but you need to use the absolute path to your website from your OS perspective (D:\projects\my cool website\)

needless to say, that address will be OS dependant

 

 

I remember watching a Chris Coyier video where he "simulated" a domain name, so even if he was in local he still had a (fictionnal) domain showing up in the adress bar

you can do that by editing your

C:\WINDOWS\system32\drivers\etc\hosts

just open it with notepad, and add a new line at the bottom of the file, like this

127.0.0.1 www.drownswebsite.com

this will tell your PC that www.drownswebsite.com sits at 127.0.0.1, which is you

Link to post
Share on other sites

When you open the files locally is it file:///c:/ in the address bar or http(s)://? When you use a path in html/php with a preceding / it's called a site root relative path and the site root is defined by your web server (Apache, nginx, IIS, etc)... Site root relative paths don't work if you're simply loading the files using file:/// and you'll have to use file relative paths or absolute paths.

Link to post
Share on other sites

Using WAMP will also allow the use of Bitnami stacks https://bitnami.com/stacks

CPU: i7 4770k | GPU: Sapphire 290 Tri-X OC | RAM: Corsair Vengeance LP 2x8GB | MTB: GA-Z87X-UD5HCOOLER: Noctua NH-D14 | PSU: Corsair 760i | CASE: Corsair 550D | DISPLAY:  BenQ XL2420TE


Firestrike scores - Graphics: 10781 Physics: 9448 Combined: 4289


"Nvidia, Fuck you" - Linus Torvald

Link to post
Share on other sites

XAMPP masterrace

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×