Hi,
How could I make Drupal (6) shows absolute internal urls instead default relative?
I'm trying to found answer for an hour and a half, but didn't find it. I guess I should modify includes/common.inc, replace absolute FALSE with absolute TRUE, somewhere in it, but don't where because absolute FALSE is appearing multiple times in it and I don't understand php yet so I'm scared to do somethhing wrong and also I'm not sure that's the way to do it. Is there maybe some module for changing relative url to absolute? I found it for img src, but I need it for all links, primary for menu and frontpage teasers.
Thanks
Comments
Mm?
Can you explain why you think this is neccessary? There may be a better solution for your actual task if you can explain it in terms of what you are trying to do, rather than how you currently think you need to do it.
Code-wise, every single link created by Drupal passes through the url() or l() functions, which do not allow for overrides.
If you think you have stronger reasons for making the CMS work like you think it should, rather than working with the links it produces and the rest of the world uses, then you can go ahead and hack core. But I think you should look at your motivations and requirements before doing that.
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
.dan. is the New Zealand Drupal Developer working on Government Web Standards
yes to what dan says, but
yes to what dan says, but also, there's one particular time where you always need to convert internal links to absolute urls, and that's when generating html content for emails.
so for example, when you're creating a newsletter using the related content module, you need to fix links sometimes. My solutions have generally be hackish (or at least, more code than I would like - overriding themes only to do this one thing), and I've often wished I had a little global variable I could toggle temporarily so that all those url() calls had an implicit absolute url.
Anybody have any ideas about this?
Absolute internal links through site
All I want is to have absolute links in menus and teasers across the site instead relative. Shouldn't it be easy to set that up?
FYI
A quick search today turned up:
http://drupal.org/project/abssrc - which looks like what you want
also
http://drupal.org/project/pathologic - which is cleverer
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Maybe pathologic
I have run into these two before I have posted this thread. abssrc is only for image sources, and pathologic seemed promising, but then I have read this:
"Pathologic is designed to only function on node content which is run through a text filter (so usually whatever's in the node's Body field). It couldn't touch menu links even if it wanted to, but as you found out, menu links do not have the problem that Pathologic is designed to solve."
so I concluded that it won't have effect on menu links. But, now I'll try it.
Thank you for suggestions.
No success
I have turn all the relative links into absolute urls by modifying url function in includes/common.inc, except site-name link that links to frontpage from every page on the site. this is the only link that is left relative. I have installed pathologic, but it didn't change it.
This is really annoying me now. I spend at least 5 working hours on this (i'm beginner to php and drupal so that could be reason for my failure). But, shouldn't it be simple to do something like this? To turn all relative paths through the site into absolute urls? It seems pretty common thing to me.
Matt Cutts quotation
And for the reason why I want to do that I'll quote Matt Cutts:
“absolute links have less potential for getting messed up [when Google indexes your page]. Even though it shouldn’t make a difference, I recommend absolute links.”
You got me.
OK, I should have guessed this was an SEO question...
I was hoping to elicit a "smart" question and describe the goal, not the step
I thought it may have been something interesting to do with offline sites or aggregation.
Ah well, good luck with that. I don't know a short answer without changing core. A long answer would be a rewrite on output, but that feels messy.
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Almost done (I guess)
I have made internal paths in content, teasers, menus absolute urls by modifying url function in includes/common.inc (line 1267 in drupal 6):
- replace on line 1272
'absolute' => FALSE,
with'absolute' => TRUE,
But there is still one link that is not affected with this - it remained relative. Site name in header linking to homepage. I have tried modifying function l, but it wasn't successful.
Should I maybe do it here (line 1335):
If yes, how? Could there be any negative side effect of modifying function url in this way? I'm new to drupal and php.
Any help will be appreciated.
a theme issue
I know this post is old, but I stumbled across it when researching this same issue.
The issue you are having is a theme issue.
The themes i've seen put the html link (not the drupal function) in for the header name and logo.
You can modify the url in the theme.
The reason I need this ability is not for an offline copy or a newsletter, but for copying.
A client told me they used to be able to copy content from a view and paste it into dreamweaver and all the links would be absolute. But now it doesn't work.
I figured something changed with his dreamweaver, but wanted to provide a solution.
We saw the urls are all relative in the source and we wanted to make them all absolute so when he pastes they will be correct.
This hack is an option. Thanks for posting your research.
Technical Architect : Philadelphia, PA
custom_url_rewrite_outbound
custom_url_rewrite_outbound() will let you alter every link that is passed through url() but be careful with it because it can be resource intensive.
http://api.drupal.org/api/function/custom_url_rewrite_outbound/6
Doing the same at Theme layer ?
Is there any way of doing this at the theme layer ?
I mean, want to have absolute links only for one theme and not for all the site.
If there is not a clean way for doing that, I will parse and modify the html output..
but as you know, this will increase the CPU / memory usage of the server... so I don't like this way :(
Thx !
Doing the same at Theme layer ?
Here is a way of doing this by parsing the html output :
http://phpepe.com/2010/05/drupal-transform-relative-links-to.html
Bumping an old thread
I have this problem too.
What I am trying to accomplish is to use a Drupal page as a template to incorporate data from a third-party system into assorted pages on our site. The most surprising thing is that it works at all!
Here's the template page:
http://www.dunwoodycommerce.org/content/dunwoody-chamber-services
The content bounded by hashes is what will be replaced with the database content, based on what link you're using in the third-party system.
Here's an example:
http://dunwoodychamber.chambermaster.com/hotdeals
Notice that the third-party content appears where it's supposed to, but the template is out of whack. Plus the links in the menus don't work, etc etc etc.
After talking to the engineers working for the system we've hired out, they tell me that this works in Joomla and even WordPress (!!!) but the caveat is EV.ER.Y link and URL has to be absolute. And I mean everything, CSS, JS, whatever, you name it. I'm going through the listing of suggestions here. Pathologic and abssrc don't work, period. No change at all. Setting paths to absolute => TRUE in the common.inc file does bupkiss. (I've set every paths to absolute across the sytem and it's just not happening.) I'm about to try the module in the last post before mine and I'll post if that does the trick.
I'm not enough of a Drupal expert to rewrite the basic site code - I'll leave that to you gurus. But this is a real life, albeit unique and weird, example of why you may need absolute paths in Drupal and it has nothing to do with SEO.
(Update - editing core is a little further than I want to go. May be time for Plan B, unless someone else has a better answer.)
Thanx, gang
Adrienne Duncan
SDOC Publishing Internet Solutions
Dunwoody, GA
No need core hacking, you can
No need core hacking, you can add this function to settings.php :
@babruix recommendation not good in conjunction with SSL
Be warned that @babruix's, elegant, simple approach, while fine on sites not employing SSL, will likely break your SSL setup.
Shai
content2zero.com
Late in noticing this
Thank you, babruix, I'll give this a shot.
(And thanks also for the warning re: SSL. However that's not an issue on our site.)
Adrienne Duncan
did it work ?
very keen to know if this works
solution found!
see http://drupal.org/node/818716#comment-4550928
awesome
thank you so much, this solved a problem i have been struggling with for ages.
are there any side effects (apart from SSL) ?
cheers
Drupal 7 solution (seems to work for me, at least)
It can't be done in settings.php, you have to make a one-liner module. I called it "absolute_urls":
absolute_urls.info
absolute_urls.module
Surely something already exists to do this?
Solution works
Thank you, uncoolbob.
Your custom module worked perfectly for me on Drupal 7.28.
I wanted to rewrite the relative urls in the Main Menu to absolute urls and this did the trick.
thks 4 help , i neet this
thks 4 help , i neet this today and when i resigned then i finde & try - works perfect
The module did not work for me
I need to change the internal (192.168..) address to my dynamic dns address. I changed the module to
But it still lists the 192.168.. addresses when I view the page source.
Ah, it does work. I also had base_url defined in settings.php