How do I change the Base URL in Drupal 7?

I've found a few things for previous versions but can't find out how to do it in D7.
Is there any documentation on this? It would be good to know if it's just changing some settings our whether I have to alter something in the database too.

Cheers
David

Comments

Charles Ferdinand’s picture

Try with this file:

Sites/Default/Settings.php

I just did a quick search and found that here:
http://groups.drupal.org/node/5242

Good luck man!
PD.
Try google

pheno’s picture

I'm runnning a Drupal 7 setup in a sub directory of root with domain access and admin 2. So it goes public_html/cms/

I changed base_url settings in settings.php and in .htaccess (the one in the root of a drupal install) and the navigation breaks on my primary site and my admin menu doesn't show anymore.

I tried both options in .htaccess with both leading to broken links and a disappearing admin menu from the main domain.

RewriteBase /cms

RewriteBase /

I'm unsure which should be used to correctly display the path or configure where the cms is.

I also changed the BaseURL in settings.php.

$base_url = 'http://cms.com';

I'm using domain acccess for 4 sites on one install. I could login through another domain, but not the main one whose URL addresses are in need of trimming as the URLs are always cms.com/cms/poetry rather than cms.com/poetry.

I got registry rebuild and ran it successfully but this did not fix the problem.

Is it understandable how the admin links, pages and navigation might be broken by changing the base url settings in .htaccess and settings.php in this way?

Is there a point in development where it is too late to change the base url?

Road Runner’s picture

If you use Domain Access you don't need to mess with .htaccess or settings.php. Actually as I recall you have to include something in settings.php that Domain Access provides but it doesn't involve the $base_url variable.

dlthomas’s picture

http://drupal.org/project/domain

Oh that sounds good - do you mean this module will this module let me change my domain name?

Road Runner’s picture

Domain Access is a straight forward way to handle sub domains e.g. subdomain1.mydomain.com, subdomain2.mydomain.com, sub3.mydomain.com etc

dlthomas’s picture

Ah right I see. I need to change the entire domain, so I guess this won't do that?

pheno’s picture

The primary domain 'cms.com' still shows a sub directory 'cms.com/cms' to all pages on the primary domain.

I just tried to redirect 'cms.com/cms' and the slash I think was an invalid character. The domain readme does say that this is unnecessary.

*edit

Domain Access is working for 4 completely different domains on the same install, the appropriate changes have been made I think and its a case of configuring base_url without breaking the links in the navigation of the site. The primary domain is manifesting the subdirectory on all its pages. The suggested changes to .htaccess and settings.php have been tried and no combination work without breaking the navigation to the primary site and the administration pages.

dlthomas’s picture

I changed settings.php and htaccess. The site loads as that URL but there are major problems with it..

Some images won't load and any links to other nodes won't work.

Does anybody know how to fix this? Surely Drupal should provide a better way of doing it than this!

pheno’s picture

No guarantees it will work, it didn't for me. It might for you :)

http://drupal.org/project/registry_rebuild

dlthomas’s picture

Thankyou. I tried this a minute ago but it still doesn't seem to make any difference.

Do you know if there's anything in the database I need to change?

pheno’s picture

I don't know if its just the database that needs changing or if its the settings in the 2 files or a combination of both. The cache got flushed so links were rebuilt, but they didn't work still, as you describe dlthomas, with only the front page working. Having a look in myphpadmin...

dlthomas’s picture

This is ridiculous. Is there really not a way of changing the domain of your drupal website without bringing 90% of it down?

To update - I've changed the url using base url and RewriteCond etc in htaccess and settings.php. It has broken all of the admin pages, all nodes and images. Basically just the front page works. So I don't know what I'm to do now.

This is what I added to my htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?newdomain.co.uk$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?newdomain.co.uk$

And this is what I put in settings.php

$base_url = 'http://newdomain.co.uk'; //

I'd like the site to be http://newdomain.co.uk instead of http://www.newdomain.co.uk but I don't know how to edit the code in htaccess to make it do that.

Can anyone tell if that's right? What else do I need to do to make the site work?... There's no way of me running updates or anything because none of the admin pages work!

dlthomas’s picture

Oh screw this I'm just going to have to install the entire website again. What a waste of time. Drupal, you are pretty uncool at the moment!

pheno’s picture

If I did a reinstall from a backup of the database, would it then work?

I did a search for URL and the subdrectory but I found not common occurrence in a table. So it might be the configuration of domain access and .htaccess and settings.php.

Checked concidences of subdirectory in slashes in the database and i have several occurrences in batch and menu router. So if I fix these I get my clean urL? :D testing... (made a backup)

mcfilms’s picture

I had an issue like this a few months back. I'm pretty sure what happened is during development in a subdirectory I had my settings set to just the root domain. So when I went to put the site to the top level of my domain, the subdirectory was included all over the place.

My solution was to dig around and find a way to run a query on my database that changed all the instances of "/dev/" to "/" and suddenly my site was back up. Alos, I think you can still run updates if you visit site.com/update.php

Good luck.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

pheno’s picture

The information in menu router is in blobs. These can't be changed in phpmyadmin, or can they?

*edit

I did a search and replace by of the database on the subdirectory string. Flushed the caches and ran update. Same problem.

I used this script to do the replace and after checking the database it seems to have worked.

http://www.brilliantsheep.com/replacing-a-string-in-all-tables-of-a-data...

Only entries in the batch table remain with the /cms/ subdirectory. The script did not change entries there and the string is in a blob also.

cfischer50’s picture

I cannot believe that in the last two days, there were others out there scratching their heads over the same problem! I have tried every combination possible in those two .htaccess files! Created redirects, deleted them, tried the multi-site thing, ... nothing! I just want the development folder REMOVED from the url. And I do not want to use the solution I'm dealing with in another situation where the lazy (or inexperienced) admin just put the all of the wordpress files and folders in public_html along side the subdomains - what a mess!

Thanks to all for posting to this discussion! Will try these suggestions next ....

pheno’s picture

I set up another domain called dev.coolsite.com

coolsite.com was the previous domain that was displaying the subdirectory cms.

I've moved the primary domain to dev.coolsite.com and the administration works there but the navigation, nodes and admin menu and links for the old primary domain coolsite.com still contain the cms subdirectory coolsite.com/cms/node .

I then decided to delete the domain and make a new entry. The issues are still persistent, even as I create new content they all carry links with the /cms/ subdirectory.

Where is the information being kept for the base url of the domain? I imagined the database because this is where many settings are kept, but I didn't find the appropriate entry. I've explored settings.php and .htaccess options and decided to just add the necessary domain access code and try to approach the problem as a domain access solution.

So how do I get to the base url settings for the domains?

pheno’s picture

I believe I found the correct .htaccess settings here:
http://www.exp-media.com/drupal7-htaccess-subfolder-tip

The registry has been rebuilt, caches flushed.The admin menu has the correct path without the subdirectory on coolsite.com but the actual admin pages still still have the subdirectory in the path.

More details here:
http://drupal.org/node/1233622#comment-4797988

pheno’s picture

It still does not work. The redirect to 3000realms.com doesn't got to where drupal is installed 3000realms.com/3000realms Which I believe are the last 2 lines of the instructions.

I edited the .htaccess so:
RewriteEngine on
# Change yourdomain.com to be your primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?3000realms.com$
# Change 'subfolder' to be the folder you will use for your primary domain.
RewriteCond %{REQUEST_URI} !^/3000realms/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you will use for your primary domain.
RewriteRule ^(.*)$ /3000realms/$1
# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?3000realms.com$
RewriteRule ^(/)?$ 3000realms/index.php [L]

It looks like something else needs to be done as file references are not working now. This is the URL for an image on the openpresence page of the 3000realms site.
http://3000realms.com/system/files/website-screenshots/Open-Presence.jpg
but the picture is actually found at:
http://3000realms.com/3000realms/system/files/website-screenshots/Open-P...

I think this issue is causing the menus to not appear too.

I got in touch with agentrickard who looks after Domain Access and says it is outside the bounds of domain access as it does not store subdirectories. I've also queried him on the possibility that as the primary domain was swapped and deleted whether something broke stopping the redirect from 3000realms.com to the CMS installed at 3000realms.com/3000realms

There seems to be several issues.

1 Rewriting the URL (This has been solved probably, unless it turns out I need another approach as the other 2 issues are addressed)
2 finding resources after the URL has been rewritten.
3 Redirecting the basic domain root to the subdirectory

Bèrto ëd Sèra’s picture

can't believe anything THIS obvious would not be documented. Most sites get developed and populated on a dev domain, then moved to production once they are ready, are we seriously saying this is not possible?

nsummy’s picture

Also subscribing. Has anyone figured this out yet? Certainly someone has the answer!

nsummy’s picture

After days of doing working at this I have fixed it. I was doing many, many things wrong, I will detail my mistakes and maybe some of you are doing as I did. I'll rank them in the order of importance as far as breaking my site goes.

A. First off, I updated my settings.php and uploaded it. At least I thought I did. I forgot to change my permissions to the file so it actually wasn't getting overwritten at all. If you are changing your settings.php make sure the settings are actually taking.

B. Run cron. I think this is a must. in 7 you can't just go to domain.com/cron.php either. Do it from within the status report

C. After these 2 things my problem was within settings.php. I looked at my old drupal 6 installation which worked and I noticed the base url variable was commented out. I commented it out on drupal 7 and voilla, my site worked like a million bucks. It defies reasoning but for some reason setting the base url (even though it was set correctly) hosed my entire site.

I will also add that the .htaccess stuff sent me on a wild goose chase. In the end I don't think that had any bearing on my problem at all.

webbykat’s picture

I've been working on this for far too long when I saw your post - my settings.php file hadn't been taking either. Thank you so much.

Xomby’s picture

Pheno's comment above worked for me.
http://www.exp-media.com/drupal7-htaccess-subfolder-tip

My setup is like this:
ROOT -> SUBFOLDER-> drupal files.

in ROOT, I set the .htaccess to:
RewriteEngine on
RewriteRule ^(.*+)$ subfolder/$1 [L,QSA]

in SUBFOLDER, I made the following changes to the .htaccess file:
1. I uncommented and modified line 100 to read: RewriteBase /SUBFOLDER
2. I commented out line 111 to read: #RewriteRule ^ index.php [L]
3. I added a line RIGHT AFTER THIS to read: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

In my SUBFOLDER/sites/default/settings.php, I uncommented line 247 ($base_url) and set it to read:
$base_url = 'http://domain.com'; // NO trailing slash! (also NO SUBFOLDER!!!)

Everything else is STOCK and unchanged.

I'm installing domain access next, will update this comment with success/fail and any additional information needed for that.

pheno’s picture

I rebooted the project and set it up as a multisite affair.
Drupal is installed to the root of the host server with the primary domain name.
Domains are added by creating subfolders in the sites folder.
The Home development is setup on Wamp and additional domains require a new database and Apache Alias.
Each domain gets its own database which is a clean solution should one need to migrate to another host.
The only disadvantage to this is that previous non Drupal domains may have trouble being set up.
Lets say I'm very keen to get Drupal 7 projects going.

I'm glad to hear you found your own ways :)

marco.falconi’s picture

Thanks, this solved for me!!

jacobstow’s picture

The link posted by Pheno and detailed by Xomby above worked a treat. This just for a single domain and installation using a subfolder.

All URLs now going to the correct place and the subfolder is invisible. Not hit any issues yet - will post back if I find anything.

Thanks!

chrisPerkins’s picture

For the correct method and best Practices. See:

1) http://drupal.org/node/776864

Happy Drupaling

Jan Syren’s picture

I had the same problem with some of the images in blogposts and I noticed in firebug that they had a full link including domain name, subfolder etc. I think it comes from the insert modul when you use that one. So I had to fix the databas it self by running the following command in phpmyadmin:

UPDATE `field_data_body` SET `body_value` = replace(`body_value`,'old-link/subfolder','newlink/subfolder')

Then I just flushed the cache and they started showing up, if you have more than one table acting up you have to do this for every table.

zigmoo’s picture

Worked for me: "drush cc all"

LaurenW’s picture

Hello,
I am having a problem similar to those above. I am running a Drupal 7 site out of a subfolder, but want to mask the subfolder. The .htaccess pointing the main domain to the subfolder seems to be working fine. But when I set the base_url to the main domain
[$base_url = 'http://www.aganosolutions.com'; // NO trailing slash!]
it breaks all the subpage links and they say page not found. If I go to http://aganosolutions.com/agano/agano-vision the subpages are all still there in the subfolder.

It does not seem to make difference if I comment out that base_url line or set it to the subfolder:
$base_url = 'http://www.aganosolutions.com/agano'; // NO trailing slash!
Then all the links work, but they show the subfolder agano in the URL.

Does anyone have any idea what I am doing wrong? Please let me know if I need to provide more information.

Thank you!
Lauren

julliard’s picture

Having the same issue, I noticed that links went broken when I export the database form the Backup and Migrate module.
Exporting and importing from phpmyadmin (all cache tables emptied) and modifying the settings.php to match the new database name (if u did) worked without problem.
Drupal instantly recognise the new base directory without any further configuration.
Tried on my localhost and on a remote server.
Good luck

brian.sanchez’s picture

I spent 30 mins to find out that this was my problem

admin/config/system/securepages
this was before:
Non-secure Base URL
http://www.domain.mx
Secure Base URL
https://www.domain.mx

and my new domain is http://www.domain.com

now
Non-secure Base URL
http://www.domain.com
Secure Base URL
https://www.domain.com

so after I made the change, works like a charm

joql’s picture

This what worked for me as I had this problem.

Background
I have a godaddy hosting account where www.maindomain.com is the main domain associated with the account but has nothing on it.

I build sites in subdirectories of it though such as www.maindomain.com/site1 etc etc and then buy a domain name and associate it with the hosting account so that they point to the correct subfolder. So for e.g. I bought www.site1.com when I had finished developing in www.maindomain.com/site1

The problem
The drupal installation didnt work from www.site1.com only the homepage would show and the navigation and subpages didnt work.

My Solution
I changed the base URL in settings.php as described by other people
BUT
I also had to amend the .htaccess and uncommented rewritebase:

# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /

This fixed it for me and I hope this info helps someone else.

alexanansi’s picture

I tried nearly everything else on this thread and still couldn't get the base url to change. In the end my solution was to export the entire database to an SQL file, then search and replace all the URLs in the file, then reimport it. Seems a bit extreme but it worked!!!

@alexanansi

mpasha06’s picture

Hi alexanansi,

Could you please update the where you replaced the URL's.
My page loads fine after adding $base_url, but some of buttons, images doesn't load.

Any help

EvanDonovan’s picture

I think in most circumstances, the answer given here should be sufficient: http://drupal.stackexchange.com/questions/33389/how-to-change-my-base-url

Nonprofit / EdTech Mentor
http://drupal.org/user/168664