Pertaining to my post here:
http://drupal.org/node/294924
I don't understand why content can't have links to files or images relative to the 'drupal root'.
For instance, if drupal is installed in public_html/web, then in node/[N] why can't I have the path:
img src='/sites/default/files/images/image01.jpg'
(FYI, it has to be: img src='/web/sites/default/files/images/image01.jpg')
Doesn't Drupal KNOW that it is installed in a directory called 'web'?
By having to include the sub-directory folder ('web' in this case) in the path, it means that drupal is not portable: I can't move the installation to the public_html root later; or rename the subdirectory; I can't create lots of pages in a test site and then copy/paste the html to a live site.
Why aren't internal paths starting with / taken to mean 'this is the drupal root'?
Couldn't Drupal be 'told' its location on the server and add '/web' in front of the internal
paths when forming the url?
Thanks for any clarification.
Comments
What is you File system path
What is you File system path on admin/settings/file-system ?
-----------------------------------------
Joep
CompuBase, Drupal, websites and webdesign
By adding raw html such as
By adding raw html such as an
tag, you are not really going via Drupal - therefore, there is no reason for it to change the address.
Magnity
http://webdesign.magnity.co.uk
Drupal 5 themes | Drupal 6 themes
You could take the issue up
You could take the issue up with Tim.
The best way to get around this is to not put your development site in a sub-directory. Instead create a sub-domain, dev.yoursite.com, then use a multi-site setup.
If you really can't do that you could setup some kind of replace script that runs on submitted content and searches for the dev URL and changes it.
Thanks for your replies. OK,
Thanks for your replies.
OK, here is the confusion I had (I think):
When *editing* the node, the url in the browser is: http://domain.net/web/node/2/edit
I assumed then that the directory of the document would therefore be 'web' (called the 'base url' ?).
On that assumption using img src='sites/default/files/images/image01.jpg' should have worked.
However, the url when *viewing* that node is http://domain.net/web/content/welcome
I erroneously thought that because 'web' is a real directory, and 'content' is just a url rewrite, that 'web' would still be taken to be the 'base url' of the node. This doesn't seem to be the case - it is the url displayed in the browser bar which is the important reference - and therefore 'content' is actually the node's location.
So instead, the file needs to be relatively linked from 'content' with:
img src='../sites/default/files/images/image01.jpg'
I know now that this is not drupal, but just the way urls and browsers work. However, it really sucks!
How does anyone ever manage to:
1) move their site from sub-directory to root or vice versa?
2) rename their installation subdirectory?
3) clone a live site in another sub directory for test/dev purposes?
4) change local-path url rewrites or url (pathauto) aliases?
I'm going to ask questions in the pathologic module project page about whether it could solve some of these portability issues for me, but any further information here about how web developers cope with the need for portability and flexibility would be welcome.
Cheers.
You can't ...
without a lot of manual sql updates.
-----------------------------------------
Joep
CompuBase, Drupal, websites and webdesign
> without a lot of manual
> without a lot of manual sql updates
Yep, that seems about the size of it.
Pathologic can't solve the problem (unless you force all internal urls to be absolute).
And IMCE has a similar unsolved thread on the project page about relative urls and dev sites.
A)
OK, so, I need the live site in '/web', which means I can't copy a dev version anywhere else except a folder called 'web', right? So what about if I made a subdomain: http://test.domain.net, and I copy the entire 'web' directory across into 'test'? So I have:
http://test.domain.net/web and the file structure is: public_html/test/web/sites/default/files/
(of course I'd also copy the DB, and edit the settings.php to use a different DB)
So, let's see...
live site internal link would be: img src='/web/sites/default/files/images/image01.jpg'
Absolute would be then be http://domain.net/web/sites/default/files/images/image01.jpg
cloned dev site internal link would be the same: img src='/web/sites/default/files/images/image01.jpg'
And absolute would then be: http://test.domain.net/web/sites/default/files/images/image01.jpg
Would this method of cloning my live site work, or is my logic flawed somewhere?
B)
Also, I'm thinking - instead of moving the live site to root in future, is it possible to use a rewrite to delete the 'web' part of the url so that it LOOKS like the site is in root? If this rewrite is possible, would it then destroy all the internal links which start with /web/sites/etc/ ?
Thanks for any further advice
Yes, using a sub-domain for
Yes, using a sub-domain for you're test site and having the test site run in the same "web" sub-directory would help a lot when it comes to moving content back and forth between the sites and having the links work.
Since you're able to setup sub-domains why not setup a sub-domain for your Drupal site? Then you don't have to worry (so much) about future changes.
OK, I've not used subdomains
OK, I've not used subdomains before, so this is what I've found out today:
If I use http://domain.net/web and http://domain.net/test/web to access the subdomains,
the relative link to an image file, on boths sites, is /web/sites/default/files/image01.jpg
This means content is transferable between the two sites. But because the path starts with /web, it means that the website will always have to be in a folder called 'web' with regard to future portability.
If I use http://web.domain.net and http://test.domain.net
the relative link to an image file, on boths sites, is /sites/default/files/image01.jpg
This means that content can be transferred between the sites *and* I can move the install to root or another subdomain in future if necessary without breaking all the internal links.
Thank you for your help getting this far.
I would have thought about subdomains if it hadn't been mentioned.
However, I have some reservations about having the main website address in a subdomain.
I'm thinking, if I use http://domain.net/web to acces the subdomain, and then I'm able to rewrite that url to read http://domain.net in the browser bar, but still actually be in the /web directory, then the relative link would probably still be /sites/default/files/image01.jpg (big question mark there! I need to test that).
With something like this in the public_html htaccess file:
# this seems to redirect the root to the subdomain
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteRule ^$ web/index.php [L]
# this looks like it deletes the subdomain (/web) from the url
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -f
RewriteRule .* web/$0 [L]
# this looks like the 'clean url' rewrite that is in the drupal htaccess, except prepending the subdomain
RewriteCond %{HTTP_HOST} ^domain\.net$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* web/index.php?q=$0 [QSA]
... When I put http://domain.net into the browser bar, it displays exactly like that, but it loads the site from the /web directory, effectively 'stealthing' the subdomain (thank you to Drupial.com for this htaccess script).
On first impression, all this completely solves my concerns regarding portability.
But I need to do a shed-load more testing before confirming that!
Any further advice is welcome.
That code is just what I
That code is just what I need! You said you need to do more testing? How is it working for you?
Believe it or not my site
Believe it or not my site still isn't live, so I haven't tested it on a production environment yet. The limited testing that I have done seems to be fine, but I think htaccess is quite server dependent. Also, whilst it seems to work fine with multi-sites, I think it would probably cause problems with some of the modules that rewrite subdomain paths; especially heavyweights like 'domain access'.
I use the exact script as above.
I found that it requires base url to be set in settings.php: $base_url = 'http://domain.net';
I would recommend that you have your dev site in a subdomain, and your main site in root though.
I'm only using this because I cannot use root, due to other people using the server for other things.