-
1. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
MurraySummers Jun 12, 2013 2:41 PM (in response to jyeager11)Do you have any skill with server scripting? That would certainly be one way to do it.
-
2. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 12, 2013 5:46 PM (in response to MurraySummers)MurraySummers wrote:
Do you have any skill with server scripting?
Unfortunately not. I know my HTML/CSS pretty well, but that's about it. I'm a designer, rather than a developer, so this falls outside my expertise.
But if it's just a matter of adding a line to the .htaccess file, I can certainly do that. Provided I know what the line is. Come to think of it, the .htaccess file sounds like the ideal place to put a solution like this.
-
3. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 12, 2013 6:32 PM (in response to jyeager11)With server side it's easy. Here's how you can do it w/ php.
Step 1. Change .html extensions on your site to .php so that your pages can process php.
Step 2. Create a new page and name it domain.php
Step 3. In domain.php define your root domain by setting a value for a variable like this:
<?php $domain = "third-party-domain.com"; ?>
Step 4. include the $domain variable in domain.php on every one of your pages by adding this line of code to very top of all of your pages:
<?php include('domain.php'); ?>
Step 5. on all of your image tags that are fetching images form thrid-party-domain.com add this line of code to echo the variable for the $domain like this:
<img src="http://<?php echo $domain; ?>/path/to/image.jpg" />
Now all you have to do is change $domain's variable value in domain.php whenever the domain that is hosting the images changes and all of the image sources on your site will be updated to include the new domain URL in the image path.
best,
Shocker
-
4. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 12, 2013 6:33 PM (in response to the_shocker)Thanks. Using PHP variable is actually within my (limited) abilities. However, I'd like the (thousands of) paths to remain unchanged. In other words, root-relative, with no extras. I just need to make the browser think it's on a different domain.
If it's not doable, then it's not doable. But I'm kind of surprised, because it seems like such a simple thing to do... especially considering all the other awesome stuff .htaccess can do.
-
5. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 12, 2013 8:10 PM (in response to jyeager11)I just need to make the browser think it's on a different domain.
If it's not doable, then it's not doable.
One would certainly hope that is not doable for obvious security reasons. .htaccess can help with YOUR domain (rewriting domain.com to sub.domain.com for instance), but not to spoof your domain for some other domain. Just think... then you could write cookie or session variable for that other domain and cause a whole lot of hurt for other domain's security, hence why it's not doable.
You can't tell browser, "hey, I'm here" when you're not actually there. However, you can tell browser on a global scale, "hey, GO here" which is what I tried to explain in the previous post.
best,
Shocker
-
6. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Mike M Jun 12, 2013 10:19 PM (in response to the_shocker)I'll add two cents worth to that... If you don't own the domain or content you're pointing to and/or don't have permission to take their bandwidth, you can add legal problems to the security issues.
-
7. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 12, 2013 10:22 PM (in response to Mike M)I own all the domains involved so it's not an issue, but thanks guys... this gives me a better idea of what my options are.
-
8. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Rob Hecker2 Jun 13, 2013 10:27 AM (in response to jyeager11)If both websites are on the same server, (they can be in different cPanel accounts) and you have the ability to edit the http.conf file, you can create an alias. You can also do this if you have WHM (web host manager) access. This will do exactly what you are asking -- it will allow you to use relative links for a location that is elsewhere.
Here is an example:
Alias /color_shared /home/mywebsite/public_html/color
The above allows any website on the server to use "/color_shared" to access the "color" directory in the "mywebsite" root.
An even simpler method is to point both domains to different directories on the same root, then they can share the files are are above their respective roots using relative paths. Actually, they can even share files that are below their respective roots.
-
9. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 13, 2013 10:29 AM (in response to Rob Hecker2)While I own all the domains involved, they are not all on the same server. Nor do I have access to anything beyond regular files (like .htaccess) that can be uploaded via traditional methods.
Are we certain that .htaccess cannot do this? Like, a simple line of code will tell the rendering to substitute all root-relative paths to another domain? It's hard for me to imagine we can't. It sounds like the sort of thing .htaccess was created for (since it can redirect to other domains, or even mirror them).
Paths must remain root-relative, like href="/image/image.jpg"
If it can't be done, it can't be done. Just want to make sure that's the case before I give up and go the search/replace or php variable route that involves changing all of these links.
-
10. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Mike M Jun 13, 2013 11:47 AM (in response to jyeager11)As the_shocker mentioned, doing it with .htaccess could open up security issues. It's pure hypothesis, but If someone were to hack this one site and get to the .htaccess file, all of your sites could then be compromised. PHP would be a better solution from that standpoint, but interlinking several sites always presents the risk of hacking of all of them as opposed to keeping them "dedicated".
-
11. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 13, 2013 11:51 AM (in response to Mike M)Wait, are you saying it would be possible, but no one wants to tell me how because it would be a security risk? Please, if you know how, just tell me and let me worry about the security risks. I am *this close* to using long urls or inserting thousands of instances of the php variable everywhere; and I would really, really, REALLY rather not do that.
Is it "not do-able" via .htaccess, or simply not recommended? There's a huge difference between the two.
-
12. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Rob Hecker2 Jun 13, 2013 12:45 PM (in response to jyeager11)It's not do-able via htaccess.
By the way, my method 2 is incorrect. Won't work that way. The only way is via alias.Otherwise, the method the Shocker described.
-
13. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 13, 2013 1:05 PM (in response to Rob Hecker2)Every method I've read in this thread - including shocker's - involves modifying all 5,000 links individually.
Again, the question is : can it be done without affecting the links. The links must remain root-relative. We simply want the browser to think that "root" is "alternatedomain.com" instead of "domain.com".
Is this do-able? Please, do not suggest that it is if your solution involves modifying all 5,000 links. I want to know if it's do-able without touching those links.
-
14. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 13, 2013 3:17 PM (in response to jyeager11)Dude, how many times do people need to say it's not doable before you realize it's not doable?!? Do you think if you keep asking the same question that somehow you will get the answer you want? Are you trying to shock the_shocker?!? I thought I explained it very clear in my last post. Again, the answer is: it's not doable.
Your last post complains about this:
Every method I've read in this thread - including shocker's - involves modifying all 5,000 links individually.
and yet your original post explains this:
One of my websites fetches its images on another server (and domain). Therefore, instead of root-relative paths, I have to use full http:// urls.
This isn't a big deal, except that the domain where these images are stored also, occasionally, changes. Which forces me to search/replace all http:// links, so they point to the new domain.
You're saying in OP that you're currently using full http:// urls and that you currently search/replace http:// links so they point to new domain. Why is it so difficult for you to do this ONE more time and find current http:// urls and replace with http://<?php echo $domain; ?>? You could of already had the first method implemented that I instructed you to do between then and now.
Let's just say for a moment, for the sake of discussion, that is was doable. To be very clear, it's not doable. This is for sake of discussion. If it was doable and you could just use relative paths you'd still have to go through and remove all the absolute domains in your links, so there's really no differene doing that than there is to replace with dynamic domain variable. Either way you'd still have to go through and modify all your links again according to the current method you explained in OP.
Captain obvious tells me that you should of thought about this before you decided to setup 5,000 links this way and then go on to forum trying to get pity from others by saying you have to modify 5,000 links. Nobody here cares that you have to update 5,000 links. Scale makes no difference in regards to your request being doable or not.
best,
Shocker
-
15. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 13, 2013 4:28 PM (in response to the_shocker)the_shocker wrote:
Dude, how many times do people need to say it's not doable before you realize it's not doable?!? Do you think if you keep asking the same question that somehow you will get the answer you want? Are you trying to shock the_shocker?!? I thought I explained it very clear in my last post. Again, the answer is: it's not doable.
And what part of "Thanks guys, this gives me a better idea of what my options are" (posted several message ago) do YOU not understand before you realize that I'm aware it's not do-able? The thread should have, could have, would have ended there if not for the fact that people kept adding to it and confusing the issue for me. If you want to make fun of how easily I get confused in matters I've already admitted not being much of an expert at, go right ahead. Certainly won't be the first time a cyberbully gets his jollies laughing at the guy who doesn't get it. Go nuts.
the_shocker wrote:
You're saying in OP that you're currently using full http:// urls and that you currently search/replace http:// links so they point to new domain. Why is it so difficult for you to do this ONE more time and find current http:// urls and replace with http://<?php echo $domain; ?>? You could of already had the first method implemented that I instructed you to do between then and now.
Let's just say for a moment, for the sake of discussion, that is was doable. To be very clear, it's not doable. This is for sake of discussion. If it was doable and you could just use relative paths you'd still have to go through and remove all the absolute domains in your links, so there's really no differene doing that than there is to replace with dynamic domain variable. Either way you'd still have to go through and modify all your links again according to the current method you explained in OP.
Captain obvious tells me that you should of thought about this before you decided to setup 5,000 links this way and then go on to forum trying to get pity from others by saying you have to modify 5,000 links. Nobody here cares that you have to update 5,000 links. Scale makes no difference in regards to your request being doable or not.
The http's mentioned in the OP are the clumsy way I am currently dealing with the issue with my limited knowledge of web development. I also mention in that very same OP that I'm looking for a cleaner alternative to this; specifically asking about the possibility of modifying just one line somewhere telling the browser to consider all root-relative links as belonging to another domain. But you conveniently forgot to mention this part when throwing the OP back in my face, didn't you?
Don't get me wrong, I appreciate that you took the time to respond at all. But given the tone of your last reply, I'm just going to go ahead and ask you to go kindly 'F' yourself with a cherry on top. Your ego clearly has an issue with my not going for your proposed solution and for that I'm sorry FOR you. So let's just go ahead and look down on one another, instead of it being just you looking down at me. Balance is important.
Thanks to everyone else.
-
16. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 13, 2013 5:52 PM (in response to jyeager11)The http's mentioned in the OP are the clumsy way I am currently dealing with the issue with my limited knowledge of web development. I also mention in that very same OP that I'm looking for a cleaner alternative to this; specifically asking about the possibility of modifying just one line somewhere telling the browser to consider all root-relative links as belonging to another domain. But you conveniently forgot to mention this part when throwing the OP back in my face, didn't you?
Unfortunately, confusion has defeated you again. I conveniently remembered to mention it by reminding you that you'd still have to go through and edit all links regardless. You just failed to comprehend. Here it is again to refresh your memory.
the_shocker wrote:
Let's just say for a moment, for the sake of discussion, that is was doable. To be very clear, it's not doable. This is for sake of discussion. If it was doable and you could just use relative paths you'd still have to go through and remove all the absolute domains in your links, so there's really no differene doing that than there is to replace with dynamic domain variable. Either way you'd still have to go through and modify all your links again according to the current method you explained in OP.
I would love to tell you to 'F' yourself for being so ignroant. Fortunately I am more mature than that, friend. Eventually you'll realize that there is no other way to accomplish the desired result other than the method I described earlier; and others concurred. The sooner you realize that the sooner I can start being accused of cyberbullying some other non-expert out there.
best,
Shocker
-
17. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
mytaxsite.co.uk Jun 13, 2013 5:44 PM (in response to jyeager11)Apart from what has already been said above, have you thought of trying "Search & Replace" in DW assuming all your files are readily available on your system under a properly/correctly defined site?
In DW you need to define a site to get maximum benefit out of it so it is worth a try.
G/L
-
18. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 14, 2013 11:40 AM (in response to the_shocker)the_shocker wrote:
The http's mentioned in the OP are the clumsy way I am currently dealing with the issue with my limited knowledge of web development. I also mention in that very same OP that I'm looking for a cleaner alternative to this; specifically asking about the possibility of modifying just one line somewhere telling the browser to consider all root-relative links as belonging to another domain. But you conveniently forgot to mention this part when throwing the OP back in my face, didn't you?
Unfortunately, confusion has defeated you again. I conveniently remembered to mention it by reminding you that you'd still have to go through and edit all links regardless. You just failed to comprehend. Here it is again to refresh your memory.
the_shocker wrote:
Let's just say for a moment, for the sake of discussion, that is was doable. To be very clear, it's not doable. This is for sake of discussion. If it was doable and you could just use relative paths you'd still have to go through and remove all the absolute domains in your links, so there's really no differene doing that than there is to replace with dynamic domain variable. Either way you'd still have to go through and modify all your links again according to the current method you explained in OP.
I would love to tell you to 'F' yourself for being so ignroant. Fortunately I am more mature than that, friend. Eventually you'll realize that there is no other way to accomplish the desired result other than the method I described earlier; and others concurred. The sooner you realize that the sooner I can start being accused of cyberbullying some other non-expert out there.
best,
Shocker
I've already addressed everything in this quote. <personal abuse removed>
How much further do you want this to escalate? Reply again so we can find out.
-
19. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 13, 2013 6:09 PM (in response to mytaxsite.co.uk)mytaxsite.co.uk wrote:
Apart from what has already been said above, have you thought of trying "Search & Replace" in DW assuming all your files are readily available on your system under a properly/correctly defined site?
In DW you need to define a site to get maximum benefit out of it so it is worth a try.
G/L
I'm pretty sure I've understood what is or isn't possible at this point. Thanks for trying to help despite the tangent this thread has taken. Looks like Seach/Replace is really the only option available, what I wanted to do cannot be done.
-
20. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 13, 2013 6:39 PM (in response to jyeager11)I just looked into an alternate method to accomplish this task. Rest assured that I was able to accomplish the result you desire with only two lines of code. It only took a few minutes to setup and I have absolutely no intention of explaining to you how it was accomplished. Perhaps I'm even more of an a****** than you thought now? FYI: it was not accomplished using .htaccess and I did not need to edit any links. I simply added two lines of code and all relative paths served images from alternatedomain.com
Too bad you're out of cherries or else you could ask me w/ a cherry on top how it was accomplished (and I would of been happy to assist you too because I really like cherries). Maybe someone else that cares enough to assist you after your little immature temper-tantrum can figure out what I did and hold your hand to walk you through it. Don't hold your breath though. On second thought... hold your breath forever.
best,
Shocker
-
21. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Preran Jun 13, 2013 7:38 PM (in response to the_shocker)Shocker, jyeager11
I am sure that when you look at this thread tomorrow after your tempers have cooled down, there will be a better resolution to this thread. Speaking for myself, I find discussions especially useful when human emotions are left out of it, especially technical discussions. And I am sure, our many users that visit this forum feel the same way too.
Shocker: It would be wonderful if you could post your answer here. There will be other users visiting this thread at a later point in time, and they will find it immensely helpful.
Good night folks, and let the peace of the night work its wonders on you.
And we are already at the weekend.
Cheers,Preran with the white flag (and a dove on it)
-
22. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
the_shocker Jun 14, 2013 8:37 AM (in response to jyeager11)<!DOCTYPE html>
<html>
<head>
<title>jQuery dynamic domain replacement in image src compliments of the_shocker</title>
<script src="http://code.jquery.com/jquery-latest.min.js" /></script>
<script>
$( document ).ready(function() {
// find <img> elements that contain www.yourwebsite.com in the src attribute
$('img[src*="www.yourwebsite.com"]').attr('src', function(x,src) {
// return a new version of the image src
// by using the replace method in jQuery
// to replace 'yourwebsite' with 'otherwebsite'
return src.replace('yourwebsite', 'otherwebsite');
});
});
</script>
</head>
<body>
<img src="http://www.yourwebsite.com/images/pets/dog.jpg" />
<img src="http://www.yourwebsite.com/images/pets/cat.jpg" />
<img src="http://www.yourwebsite.com/images/toys/hamster.jpg" />
<img src="http://www.yourwebsite.com/images/toys/donkey.jpg" />
</body>
</html>
best,
Shocker
-
23. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
jyeager11 Jun 14, 2013 1:30 PM (in response to jyeager11)I abandoned this thread for obvious reasons, but I figured I'd come add one last posting to highlight the fact that it took only 5 minutes in another forum to learn that there's a basic HTML tag compatible with all major browsers that does exactly what I was asking.
"The <base> tag specifies the base URL/target for all relative URLs in a document."
http://www.w3schools.com/tags/tag_base.asp
Seems rumors that "it can't be done that way" were greatly exagerrated. Given the amount of arrogance and condescension used in communicating this impossibility to me, you'd think this person would at least know what he's talking about.
Not only can it be done, but it doesn't even require the slightest bit of trickery. Just a simple line in the header, which was my dream scenario.
Thanks again to others who commented without being complete jerks. Hopefully this information helps you as much as it helps me.
-
24. Re: Can a site tell the browser to consider all (root-relative) links as belonging to another domain?
Preran Jun 14, 2013 1:32 PM (in response to jyeager11)Now that we have come full complete cycle, I am locking this thread in everyone's best interests.
Have a wonderful weekend, everyone!




