URL HTML links and links

I have the following problem:

The URL is http://www.myhomeurl.com/application1/ , and the base is:

<base href="http://www.myhomeurl.com/"/> 

All resources like images, css and javascript will be:

 http://www.myhomeurl.com/css/myfile.css http://www.myhomeurl.com/js/myscript.js http://www.myhomeurl.com/images/img.jpg 

BUT, the link will be to "application1", for example:

 http://www.myhomeurl.com/application1/page1.html http://www.myhomeurl.com/application1/page2.html http://www.myhomeurl.com/application1/page3.html 

The question arises: how to use the base URL for resources (for example, css, js, etc.) and use the base / application1 links for page links?

Here is the problem when I have:

 <a href="page1.html">Click me!</a> 

When a user clicks on this page, the page will be:

http://www.myhomeurl.com/page1.html

but not:

http://www.myhomeurl.com/application1/page1.html

+4
source share
8 answers

You can use the base tag and modify it so that all the URLs can relate to the application base.

 <!DOCTYPE HTML> <html> <head> <base href="http://www.myhomeurl.com/application1/" /> </head> <body> <!-- content --> </body> </html> 

Further information can be found at http://www.w3schools.com/tags/tag_base.asp

edit: the w3c specification on the base tag http://www.w3.org/TR/html4/struct/links.html#h-12.4 also illustrates how to pull images from other places.

+3
source

Change it on your resources

 <link href="./css/myfile.css" rel="stylesheet" type="text/css" /> 

I do not like

 <link href="http://www.myhomeurl.com/css/myfile.css" rel="stylesheet" type="text/css" /> 

And your base looks like this:

 <base href="http://www.myhomeurl.com/application1/"/> 
+2
source

Use this variable in the HTTP_SERVER link

 define('HTTP_SERVER', 'http://www.myhomeurl.com/application1/'); <a href="<?php echo HTTP_SERVER?>myurlpage/page1.html">Click me!</a> 
+1
source

you should have something like this

 root root/css root/js root/files/html1.htm root/files/htmml2.htm 

root will be nothing more than the /// name of your site

 http://www.myhomeurl.com 
0
source

Define two constant for your resources css, js and one for links and use them in the application: -

 define('RESOURCE_URL','http://www.myhomeurl.com/'); define('LINK_URL','http://www.myhomeurl.com/application1'); 

so if there is any change in the base url you can only look at these constants.

0
source

I'm a little late to this question, but I see that none of the answers do what (I think) you need.

I suggest you use (as others have said) a base url like this:

 <base href="http://www.myhomeurl.com/application1/" /> 

This way your links will work as intended. Then, when you add resources, you only need to go to the parent directory, for example:

 <link href="../css/myfile.css" rel="stylesheet" type="text/css" /> 

or

 <style type="text/css"> @import url(../css/myfile.css); </style> 

Pay attention to ../ , telling the browser to exit the "application1" directory, going one step in the file structure.

Hope this helps :)

0
source

I would start putting all the links with / and the top directory of the URI. This makes them relative to the domain. Then just put the protocol and domain into the database.

0
source

when using the base url you should not put www. into it.

Then, if your url is mysite.com and your application is in mysite.com/app , then you will set mysite.com/app for your base, when you use your info.html example, it will look like mysite.com/app/info.html .

You can also use ../app/info.html and it will look like mysite.com/app/info.html

0
source

All Articles