Drupal installed in subdirectory but made to appear in root
pulsifer - May 17, 2007 - 03:43
FYI, a Drupal installation tip.
In order to keep all the Drupal files together, I wanted to install it into the ~pageroot/drupal/ subdirectory of my web server, but I didn't want to have to access it via http://www.mysite.com/drupal/ -- I wanted to access it as if it lived in the root, at http://www.mysite.com/.
Here's my solution:
In the root, I placed an .htaccess file that contained:
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule .* http://www.mysite.com/ [L,R=301]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]Then in drupal/.htaccess, I disabled the mod_rewrite instructions by changing "<IfModule mod_rewrite.c>" to
<IfModule XXXmod_rewrite.c>Finally, in drupal/sites/default/settings.php, I uncommented the line
$base_url = 'http://www.mysite.com';Not sure if there might be a better solution, but this seems to work fine.

have your host point to the subfolder as root
I do the same as you are wanting with many sites. It has benefits far beyond what you get through your solution... and does not require modifying .htaccess files
I use dreamhost (i am sure many other hosts have similar options) and specify example.com/drupal as the web directory for the domain.
--> when people visit example.com what they actually access is example.com/drupal.
Hope this is clear
c.
Avolve, I like your
Avolve, I like your suggestion but just thought I'd point out my experience using hostmonster. Using hostmonster, specifying the web directory is possible for addon domains but **not** the primary domain.
Also, the content for each addon domain is stored as a subfolder of the primary domain folder (public_html).
If you only change your mind later
I also use dreamhost. I installed in a /drupal folder and everything worked fined except that my 'clean' url (www.mydomain.eu) showed a file listing of the directory, not my initial page.
After I changed the web directory in the dreamhost panel to mydomain.eu/drupal, I got plenty of 'page does not exist' errors in my site.
I had to edit /drupal/sites/default/settings.php and remove /drupal from this line:
$base_url = 'http://www.mydomain.eu'; // NO trailing slash
Just to confirm, there is no need to modify the .htaccess file.
perfect Solution
really perfect solution...it helps me to clear my root and to be clean as much as possible
until now there is no any problems
there is only one missing clue....until now i did not install my SSL Certificate ...i wish i do not see any problems because of rewriting condition
i will try and be back ;)
can you get clean urls with this htaccess
looks like a very clean solution.
can you get clean URLs with it?
this may be the solution for me
What you've talked about may be the solution to my Drupal website. I uploaded drupal to my site about 2 months ago. For reasons I don't remember now, I placed the drupal 5.1 folder right underneath the the public_html folder. I fiinally get back to this drupal project and just realize that my web server recognizes only index.html or index.php at the root level as the home page. To comply with this rule, I thought my options are
1. move all drupal files to the root level
2. in the root level index.php, redirect to the drupal index.php.
I wasn't quite sure which way is better until running into this thread. I think the solution of interest here is the 2nd option above. I'll appreciate greatly any suggestions from you. Thanks,
Warren
Thanks a bunch
OK, I tried it and it worked like a charm.
I am still having problems with some of my multy site pointing to the original site. but hope to get that fixed soon.
for some reason pointing my browser to www.second_site.com displays www.first_site.com
any ideas? - I guess it must be realted to the www.mysite.com rules in the htaccess.
Great ... just one question
Your htaccess script works great on requests with HTTP_HOST= www.mysite.com! Thank you!
However, it also appears to process requests from any domain, not just www.mysite.com, including:
subdomain1.mysite.com
subdomain2.mysite.com
subdomain3.mysite.com
www.anothersite.com
subdomain1.anothersite.com
subdomain2.anothersite.com
subdomain3.anothersite.com
I want it to leave those alone ;)
If the script is supposed to leave those other domain requests alone, is it possible that it requires a particular flavor of Apache? (My host runs 1.3.37 on Unix.)
If not, is there any alteration that will just pick up that one HOST domain and leave the rest?
Its these two lines that
Its these two lines that make it redirect all hits to www.mysite.com
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]RewriteRule .* http://www.mysite.com/ [L,R=301]
If you want to only rewrite hits to www.mysite.com, and leave everything else alone, you would need to replace the rewrite rules with something like this:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]RewriteRule ^$ drupal/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
Perfect!
As someone who is not familar with the subtleties of rewrite syntax, I have to bow very low and say thank you.
I suspect that there are others who want to host multiple Drupal domains — along with static domains and subdomains — all in one Apache account and with one MySQL database. You have made that possible!
thanks and a question
Hi Pulsifer,
I am using a slightly modified version of you rewrite rules:
Options -IndexesRewriteEngine on
Options +FollowSymLinks
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*wiki.*
RewriteRule .* drupal/index.php?q=$0 [QSA]
This enables me to have all my muti sites on the the same installation AND have drupal installed in public_html/drupal
I am no trying to install a wiki at public_html/wiki and set it with short URLs, but no matter what I do, drupal "steals" my WIKI's short URLs.
any advice?
thanks,
Udi
Multi-site .htaccess not working for uploaded files
Ok, so after having everything generated through index.php working fine, I discover that files aren't passing correctly.
For example, this is working ...
...however, this isn't ...
I should add that I'm seeing the files fine via ftp, they're just not being delivered through http via the htaccess instructions.
Thoughts?
FOLLOW-UP
For anyone who is reading this thread: the htaccess instructions, above, work fine ...
The file system path has to reflect a /files/ directory inside the specific site that is being referenced.
Then it works fine!
with and without www
I wanted to handle both www.mysite.com and mysite.com,
so I basically added another copy of your rules but without "www" and it seems to be working so far (not that I know why).
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^$ drupal/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
RE: with and without www
Thanks. I did exactly the same thing (on Drupal 5.3) with the same results (ditto on the "not that I know why").
BUT
Although all the page requests seem to be getting resolved correctly (both within and without Drupal), I'm seeing tons of "page not found" entries in the Drupal log (for non-drupal pages) - even though those pages actually seem to be loaded OK.
details:
drupal lives in a subdirectory off the base (httpdocs in my case).
Several other non-Drupal pages/sites also live off the base, e.g.:
(base)/drupal
(base)/abc
(base)/def
etc.
- mysite.com (and www.mysite.com) resolve (or are redirected?) to the drupal site.
- URLs like: mysite.com/abc/index.php, mysite.com/def/index.html seem to load the non-drupal sites just fine.
- If I access a non-drupal page: http://mysite.com/abc/index.php - the page loads, seemingly correctly, but the Drupal log shows "page not found" errors for things like:
abc/CSS/foo.css
CSS/foo.css
Notes:
1. I did set the $base_url in settings.php to http://mysite.com
2. I did not touch the .htaccess file in the drupal subdirectory.
3. I'm sure that all the non-drupal sites use relative URLs in their html to access their own subdirectories. e.g.: link href="CSS/foo.css" rel="stylesheet" type="text/css"
Any insights? Thanks!
Sub-domain clean urls
Ok, I've got the exact same code as above to make it appear that Drupal is installed in the root. It works (thanks to this thread).
I've since created a sub-domain called develop. So is accessed www.develop.mysite.com . Initially I made the sub-domain folder a symlink which pointed to the Drupal installation folder (mysite.com/drupal). I correctly set up my Drupal 'sites' directory to account for 'mysite.com' and 'develop.mysite.com'. This all worked and had successfully created my first Drupal multi-site set-up.
My problem is that I can't activate clean url's for the sub-domain 'develop'. Drupal (6.1) administration page has disabled my ability to enable clean url's. As the 'develop' folder is only a symlink there is no way to create a .htaccess file for that folder (or is there?).
If I want clean url's for the sub-domain, how do I handle this situation?
My attempts so far have led me to deleting the symlink 'develop' and creating a normal directory 'develop'. Within the 'develop' directory I created a .htaccess file based upon the RewriteRules as suggested in this thread. I'm stuck. Can't even get the sub-domain up and running under this method.
Any advice most welcome.
__________________________
Steven Taylor
Melbourne, Australia.
http://superjacent.net/cms
Woohooo it wooorrkss
Woohooo it wooorrkss
Amazing! I didn't believe
Amazing! I didn't believe this was possible without major Drupal surgery, but its seems to hold against everything I have thrown at it so far!
Multiple domains
The second version is especially powerful for multiple domains using both Drupal and static content.
True. I didn't mean to use
True. I didn't mean to use it actually -- I simply use domain pointers, and with this solution I would be afraid to modify .htaccess for other things that I wanted. But it is an elegant solution to a problem which has puzzled many people.
Non-Drupal domains
Hi pulsifier-
The second version of your htaccess code works like a charm for a Drupal-delivered site, in that it makes sure URLs are handled according to Drupal processes, including clean URLs. Bravo.
I also want to pass non-Drupal domains into another subdirectory, leaving the entire path intact. (Again, I'm not skilled with rewrite syntax. ;( Which rules would go away in order to leave the paths for a non-Drupal domain?
I'm making a donation to Drupal for your help on this. It deserves attention at the highest levels ...
-jay
.htaccess for non-Drupal domains
I found the answer to my own question.
Here are instructions for rewriting domains for static (non-Drupal) sites to subdirectories in a site with parked domains:
http://www.bluehostforum.com/archive/index.php/t-288.html
-Jay
.htaccess content
I'm trying to achieve the same end, to make my drupal subdirectory think that it is the /root.
However in my drupal subdirectory .htaccess file there appears to be 2 similar sections using the IfModule mod_rewrite.c tags, an automatically generated one at the start of the file (which instructs not to edit) and another further down......which did you mean?
Which if statement?
The first if statement appears to surround an expiration rule; I didn't change it.
# Reduce the time dynamically generated pages are cache-able.<IfModule mod_expires.c>
ExpiresByType text/html A1
</IfModule>
The second surrounds the rewrite rules; I did change that one.
# Various rewrite rules.<IfModule XXXmod_rewrite.c>
RewriteEngine on
I didn't find a second IfModule mod_rewrite.c statement.
The process is working fine for me making the changes in this way.
thanks. [subscribe to
thanks. [subscribe to thread]
Not working for me
I have a multisite, so I used the second .htaccess fix and put that in ~/public_html/ with only partial luck.
NOTE: The mod_rewrite.c suggestion messes up my site2 (I get in and see content, but all the links are broken). And, for multisites, the settings.php change must occur in drupal/sites/site1/settings.php not the default directory.
The /drupal/ is not needed for any pages (good!)
BUT...
Some links go to a Drupal "Page Not Found" page. If I go to www.mysite1.com, which is linked from the "Title" at the top left and from "Home"...I have to navigate specifically to www.mysite1.com/index.html (since that's what I have for my URL alias of the front page).
Also, if I go to mysite1.com I get a non-drupal "Page Not Found"
Any suggestions?
A small improvement
I tried udijw's .htaccess code and that gets rid of the non-Drupal "Page not found" when the www is omitted (ie, now I get the same Drupal version of "Page not found" with and without www). I still would like suggestions for how to avoid the "Page not found" completely.
works now
I just needed to re-set the frontpage URL in Home » Administer » Site configuration
Clean url is a good
Clean url is a good choice.
----------------------------------------------------
accounts mart
What effect does this
What effect does this solution have on Search Engines?
----
Darly
Not working for me...
I would love to make this work for me so I don't have to put Drupal in my root, but it's not working out that way. Here is the .htaccess file I put in my root:
Options -IndexesOptions +FollowSymLinks
RewriteEngine On
RewriteRule ^$ drupal-5.3/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal-5.3%{REQUEST_URI} -f
RewriteRule .* drupal-5.3/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal-5.3/index.php?q=$1 [L,QSA]
I uncommented the line in setting.php, but I did it for sites/mydomain.com/settings.php Is that a problem?
I didn't have a .htaccess in drupal-5.3 so I created one with just that line. Is that the problem? I saw elsewhere in this thread another user didn't need that step.
Also, what role does setting up a symlink play in this procedure?
Thank you in advance.
Set up drupal first
This only changes the way the URL looks, so you should be able to have a working drupal set-up where it is not installed directly in your Root without changing any of the things listed here. You should try this only after you have your website working and you can navigate to it from mydomain.com/drupal-5.3/
You'll only need symlinks if you are doing a multisite install or if, for some reason, you don't put the drupal installation in a subfolder of your webroot folder.
Redirect links from subdirectory
The first post works great -- thanks! However, I'm looking to take things a step further -- my drupal install is in a subdirectory called /content/, and while the above allows me to keep the install in /content/ while removing it from the url, there are incoming links with /content/ from third party web sites and search engines.
Ive been trying to redirect /content/ with this added as another line to the root htaccess:
RewriteRule ^/?content/([a-z/.]+)$ /$1 [R=301,L]no such luck though, any suggestions are appreciated.giving drupal precedence in htaccess?
Think I may have a slightly similar problem to 'bsuttis'. I have an old site which I have now 'converted' to drupal. I have the drupal installation in a sub-folder called /drupal. I have used the htaccess as above and am really impressed that it works..however..
I have used url aliases in drupal to match my old article urls so I dont get broken links from other sites...when I apply the htaccess, as descibed at the beginning of this post, drupal is not taking control. What I mean is, instead of showing the new drupal alias (e.g. www.example.com/archive/story.html) it shows the old version (which is obviously still on my server). OK, if I delete the old file drupal then takes control, but surely there is a way in the htaccess to control whether drupal has precedence or not??
giving drupal precedence in htaccess?to clarify
just to clarify...
in the htaccess it looks for the old file first then if it is not there drupal takes over...what I want is for drupal to take control first and if it is not a drupal page it is at least picked up by the 'old look' static site page with the same url.
thanks
redirecting old urls
I'm with bsuttis: I want to change the URLs on my site to make it look like drupal is installed in the root directory, but I need to redirect the old URLs so they're not lost to search engines, bookmarks, etc.
For example:
- Drupal is installed in /drupal and has been running there for a long while (i.e., URLs are well known to SEs, etc.). A common URL for a node might be: http://mysite.com/drupal/post/this_is_a_node
- I now want it to appear as if the site is based in the root dir as far as the visible URLs are concerned: http://mysite.com/post/this_is_a_node
The solutions posted here do the above just fine.
- I also need to keep the old URLs (with 301 redirect); e.g., http://mysite.com/drupal/post/this_is_a_node still loads the proper node by redirecting to http://mysite.com/post/this_is_a_node
I've tried numerous combinations of additional rules, both in my root .htaccess and /drupal/.htaccess, but no combination has shown any promise--again, similar to bsuttis. So far, there haven't been any working solutions posted here, elsewhere on drupal.org, or anywhere else that I've been able to find. Has anyone actually solved this problem yet?
Thanks much.
redirecting old urls!
I think I found the answer to this. My root .htaccess is pretty much what was originally proposed in this thread, plus the changes to drupal's .htaccess, plus the base-url change (leading Drupal to believe it's in the root dir). I also added to my root .htaccess bsuttis' rewriterule meant to enable use of the old URLs, redirecting them to the new ones (minues the "/drupal" in the path). The final piece was renaming drupal's actual directory from "/drupal" to, say, "/drupal4", and adjusting .htaccess accordingly. Note, though, I kept bsuttis' old-URL-redirect referencing "/drupal", a now nonexistent directory.
Here's my root .htaccess:
# Now if it's anything but mysite.com, fix it
RewriteCond %{HTTP_HOST} !^mysite\.com
RewriteRule (.*) http://mysite.com/$1 [R=301,L]
# Check for old /drupal-based URLs and remove /drupal
RewriteRule ^/?drupal/(.*) http://mysite.com/$1 [R=301,L]
# Make drupal the home page
RewriteRule ^$ drupal4/index.php [L]
# If an actual file exists in drupal4 dir, prefer it
RewriteCond %{DOCUMENT_ROOT}/drupal4%{REQUEST_URI} -f
RewriteRule .* drupal4/$0 [L]
# Otherwise change behind-the-scenes URL to drupal4
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal4/index.php?q=$0 [QSA]
Notice I fix the domain name first and don't bother checking it subsequently; just my personal choice. Next is the redirect for the old "/drupal" paths previously bookmarked by visitors, RSS readers, and search engines. Then, the rest is the same as was originally proposed, except that the "/drupal" path is now "/drupal4". So far, this seems to work like a champ, but please let me know if you see any problems with it.
Works for me
Confirming that the code works for me, thanks much Wayne.
Possible to fetch any subdomain (www.domain.com etc.) with this?
Is it possible to fetch any subdomain (like www.domain.com, en.domain.com, de.domain.com etc.) with this rewrite rule? What has to be changed?
Thanks, -asb
Edit: I found out how to do this:
RewriteRule ^olddir/(.*)$ /$1 [R=301,NC,L]where "olddir" is a path like www.example.com/olddir, that is redirected to www.example.com. All content index by search engines can be transparently accessed with this redirect.
Front page problem
Hi i am having a problem with the front page which should be node listing page, everything is working ok, when drupal is in the root on my hosting account, but I put it in the subfolder and I am using mod_rewrite to hide the subfolder in url.
Both menus that link to home page are set to
<front>.So when I look at the article in one language and then click on the same article in other language, and then click on the home page, I am always getting the default language home page even if the menus are on the other language.
I do hope this is clear, anyway you can see the problem on www.spc.yu
I am using the following setting for mod_rewrite
here is .htaccess file in the root of my hosting account
Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^$ cms/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/cms%{REQUEST_URI} -f
RewriteRule .* cms/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ cms/index.php?q=$1 [L,QSA]
and the in cms/.htaccess file I changed
<IfModule mod_rewrite.c>to<IfModule XXXmod_rewrite.c>and in settings.php I uncommented the line
$base_url = 'http://www.spc.yu;
Any solution?
Issue with images
I've storys with images loaded that aren't getting displayed now...anyone have any ideas of what else i need to change?
figured it out...i didn't
figured it out...i didn't change www.example.com to my own domain!
Is it working with Drupal 6 ? (Yes)
I have drupal 6 RC2, and while the solution works for rewriting URL's I have had all subdirectories below drupal not accessible by Drupal itself and generating "Page not found" errors.
I have discovered that those statements do not work with my hosting provider
RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{DOCUMENT_ROOT}/mysubdir%{REQUEST_URI} -f
After fighting with various trials and errors , I have tweaked the settings as below :
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
#site
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mysubdir
RewriteRule ^$ /mysubdir/index.php [L]
#files
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^.*\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_URI} !^/mysubdir/
RewriteRule ^(.*)$ /mysubdir/$1 [L,QSA]
#url 's
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mysubdir
RewriteRule ^(.*)$ /mysubdir/index.php?q=$1 [L,QSA]
.. and it seems to work. Hope it helps someone else.
Sorry - but here it goes
I am so new to all these, so please...
I also have drupal installed in shared hosted environment in www.mywebsite.com/drupal directory
I was trying to follow your instructions, however:
1. i do not know what is the easiest way to modify files that are located on the hosted server - when I download them on my PC and open with notepad - they come in a way that's hard to read and modify;
2. i noticed that there was already file in root directory of www.mywebsite.com with the name .htaccess - should I delete this one and replace with the one you mentioned?
Thanks!
I may be wrong, but here's what I think
1. Try Wordpad instead of Notepad or try another text-editing program. I use UltraEdit and I love it...it's not free, but it's not too expensive.
2. Open the .htaccess file in your text editor and see if it contains anything...it might be empty. If it's not, just add the new text recommended here to the existing .htaccess.
I use Notepad++, GPL and
I use Notepad++, GPL and free.
hope that helps
Can't login anymore: access denied
I used the above description with Drupal 4.7 and it seemed to work nice because I could access the page from the root. The problem was that I couldn't access the admin section anymore. I was able to login and saw my user menu but any further click would give me an "access denied" error.
I "solved" it temporarily by installing Drupal 6 and doing the same changes proposed here in the thread. During the first day of my installation all way working well, I could even log in and do changes to my site.
However now, I am suddenly getting the same errors over and over again: access denied. Can't administer my site anymore.
Deactivating CleanURLs didn't help...
What is causing this? Is it maybe a cookie error? Help is greatly appreciated!
Solution
I reverted all the changes suggested in this thread. But the login problem remained. I got the access denied message over and over again.
After reading through "access denied" threads for hours without finding any solution, I finally found the solution in this post http://drupal.org/node/92517#comment-169664
Adding session_write_close() at the end of index.php solved it for me!
(1) I did as you suggested
(1) I did as you suggested but it does not point me to the drupal database.
(2) I place drupal in the subdir www.mysite.org/www/DRUPAL (caps)
(3) I changed the root .htaccess. The 'mysite' is changed to my domain name. 'drupal' is changed to 'DRUPAL'. I deleted the original contents in the root .htaccess.
The deleted original contents are:
Options +Indexes
php_value error_reporting 7
php_flag display_errors off
(4) I changed the drupal .htaccess as suggested.
(5) The www.mysite.org/www/DRUPAL/sites/default/settings.php already has the line commented out. So no action there.
......
But it does not work :(
I read as many posts here as i can find and did my best to find out the source of the problem. Can someone help please? Thank you.
Summarize?
I'm pretty new to mod_rewrite rules and .htaccess altogether. I was wondering if someone could summarize the different methods for the different situations. There seem to be many methods listed in the post and I'm confused as to which one I'd need. I think it would also help others with similar problems.
My dilemma is as follows:
- I host many sites, both drupal and non-drupal
- My primary domain (primarysite.com) is running via drupal 6
- I would like to host my primary domain under ~/public_html/primarysite/drupal_files_here, instead of under ~/public_html/
- I would like primarysite.com to display as primarysite.com instead of primarysite.com/primarysite/
- I need secondarysite.com which resides under ~/public_html/secondarysite to be unaffected and display as secondarysite.com
Any advice?
Got it...
My setup:
I want my primary domain to reside in a subdirectory under /public_html so I have added some rewrite rules. However, before we get to that I'm running the following types of sites on my shared webhost:
- static
- drupal 5.x
- drupal 6.x
Drupal 6 runs my primary domain which i have in a subfolder called primary. Its path is ~/public_html/primary and all the drupal 6 files reside here. It will not contain multiple sites.
For simplicity, we'll say that my static site sits under ~/public_html/mystaticsite.
Using the following code in my ~/public_html .htaccess file:
Options -Indexes
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.myprimarysite\.com$ [NC]
RewriteRule ^$ primary/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.myprimarysite\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/primary%{REQUEST_URI} -f
RewriteRule .* primary/$0 [L]
RewriteCond %{HTTP_HOST} ^www\.myprimarysite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* primary/index.php?q=$0 [QSA]
and by setting my ~/public_html/primary/sites/default/settings.php baseurl to:
$base_url = 'http://www.myprimarysite.com'; // NO trailing slash!my static and drupal 6 sites work great. If I go to www.myprimarysite.com i am redirected to ~/public_html/primary and it does not display /primary in the URL. Also, it does not effect www.mystaticsite.com or any of my drupal 5 sites (which is a multiple site installation with sites pointing to a ~/public_html/drupal directory)
All of my static sites are true add-on domains through the cpanel and so are my drupal 5 sites. The drupal 5 sites just point to ~/public_html/drupal directory since drupal is able to render the appropriate site based on the sites folder.
STyL3, I am glad you got it.
STyL3, I am glad you got it. :)
but can you please further explain how the above code made you manage each site separately? (As I cannot see any www.mystaticsite.com in your syntax)
I was looking for a solution very much similar like yours.
[I am poor in rewrite syntax .. sorry] but I was looking for a solution of multiple installs (not one multisite install) .. with every install in a separate subfolder. And I want to place a htaccess file in the root to manage both domains.
For instance:
www.firstdomain.com points to root/domain1
www.seconddomain.com points to root/domain2
via .htaccess of course (since other methods like symlinking for example or vhosts cannot be managed on shared hosts .. and you are left with .htaccess method)
I assume someone can help me with that. ;) Is this feasible? Or do I have to resort to multisite and spare the fuss?
Thanks
only one .htaccess file needs to edited
Bassio-
I only edited the .htaccess that sits directly under /public_html. There was no need to have any other information in the file (regarding static sites or other drupal sites) since they did not share the same domain name. The above .htaccess file will allow all sites to go to their respective directories (it just leaves them alone and does not do anything to the request). However, if someone requests www.primarysite.com it will direct them from /public_html to the /public_html/primarysite folder and rewrite the url - displaying www.primarysite.com instead of www.primarysite.com/primarysite.
Does this help?
Still unclear about redirecting combined with rewriting
It looks like if someone uses
www.myprimarysite.com/about-me it will fetch
www.myprimarysite.com/primary/about-me.
That's great. But what about if someone types in or the menu shows
www.myprimarysite.com/primary/about-me?
Won't that fetch the same page and display the full URL? One of the issues that I run into is that my menus include the "/primary/" in their links, so that is what the user sees when they use my menu (if someone has an idea about how to handle the menu issue, I'd appreciate it).
Maybe this is naive, but I'm concerned that redirecting
www.myprimarysite.com/primary/about-me to
www.myprimarysite.com/about-me
in addition to the rule you have to hide "/primary/" could lead to an infinite loop. Is that not an issue or is there a way to make sure that there isn't a loop while making sure that the user always sees the version without "/primary/"?
Thanks
Always amazed......
that this most obvious needs are not so easy to implement. At least for a newbie like myself.
Nevertheless, I have the same situation, except I have a test site on my new host's server. See details at http://drupal.org/node/236106 which I created before I found thread.
I also have not pointed my domain to my host yet as my non-drupal site is still running on a different host server. Would hate to implement the changes, point my domain to my new host and find that it does not work.
So is there any way to test whether this will work before I point my domain name to my new webhost? Thanks for your help and contribution. I would be totally lost without this thread.
The 'Obvious' thing to do is
The 'Obvious' thing to do is of course place your files where they are expected to be.
Anything beyond that is slightly tricky, depending on your abilities.
Options include:
- having a webhost who realizes this is not really that big a deal, and provides a control panel interface that lets you define where your webroot is served from. This comes with scale. It's just not needed or appropriate for small out-of-the-box hosting packages, but is handy when you really start running multisites.
- experimenting with symlinks. Useful sometimes, but probably out-of-scope for cheapo hosting packages also. Also probably not a great idea when you have already put your files in a subdir of the 'target'. Could get messy.
- Just bung in a redirect page from the top. Super-easy, but you have to live with the subdirectory in your URL. Bonus however is is you can run other stuff alongside with no conflict.
- Getting enough control of your server to edit your own apache configs and just do it the way you want. Requires knowing what you want, how to do it, and a non-trivial hosting package.
- Actually figure out what you want from telling the browser one things and the server another to alias/redirect via .htaccess redirects. Yes it's messy, but it's only a work-around because you've chosen to forego all the above proper ways to do it. rewrites are usually cheats. Nifty ... but cheats, because they are lying to the system :-)
ANYWAY. As you've chosen option E ... yes, you do want to test :-)
It's probably covered elsewhere, but
BEFORE changing your DNS propogation etc, preview the site as if the DNS propogation had already happened.
Do this by editing your c:\windows*\system32\drivers\etc\HOSTS file to include your domain name and the new hosted IP.
This lies to your personal machine about where to go to find the website.
The website is already listening for requests on that IP ... although no-one is (yet) looking there for it.
You will now be the only machine that knows to ask that host machine for that named website.
It'll be happy to respond privately.
Test and fix any problems you find.
Your existing/old site will be inaccessable (to you) while this hack is in place. Undo it to put the internet back to normal. No restarts needed usually, but I dunno, you may have to close your browser session, depending.
Pay attention to the difference between yoursite.com and www.yoursite.com. Use one, the other or both, but do it consistantly.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
Do you know any such webhosts
that deal with option A and provides that control panel access? Mine has essentially abandoned me. This is not an el cheapo hosting package either, but they don't really support drupal. A friend used them and I thought I could manage. Lesson learned is that I need a higher level of support.
Will try what you proposed and also what the next commenter suggested. But I will ultimately change hosts.
I'm using (among others)
I'm using (among others) Servage.com
and it made me smile when I saw that feature.
Makes testing sites totally trivial also, as I can just switch from having
[ http://demo.mysite.com/ => /home/xxx/xxx/domains/www_v2/ ]
to
[ http://www.mysite.com/ => /home/xxx/xxx/domains/www_v2/ ]
without file copys, backups or config strangeness.
and, yes, I built a drupal install underneath siteroot in /home/xxx/xxx/domains/www/drupal5.1/
But when I was ready, I just set
[ http://www.mysite.com/ => /home/xxx/xxx/domains/www/html/drupal5.1 ]
and it went. And I knew I could flick back.
Also runs great with Drupal multisite, as I have
[ http://personal.mysite.com/ => /home/xxx/xxx/domains/www/html/drupal5.1 ]
[ http://reference.mysite.com/ => /home/xxx/xxx/domains/www/html/drupal5.1 ]
(All going to the same place)
and that triggers the respective
.../www/html/drupal5.1/sites/personal.mysite.com/settings.php
.../www/html/drupal5.1/sites/reference.mysite.com/settings.php
etc ad infinitum. Same codebase. Which is the point of multisite.
I have other issues with Servage at the moment (Not the fastest, and a troubling security vulnerability recently) but the features are great.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
I'm also with Servage.net
I'm also with Servage.net I posted this http://drupal.org/node/144643#comment-775981 (this thread) a few hours ago. I got a multi-site up and running but having problems with clean url's for the sub-domain site. Can you please advise on what method you used to point your sub-domains to your Drupal core and how you resolved clean url's.
Thanks in advance.
___________________________
Steven Taylor
Melbourne, Australia.
http://superjacent.net/cms
As described above, I just
As described above, I just did:

Control panel : Web Server : List Virtual HostsI dunno what side effects symlinks will have, or whether they behave the same all the time. Apache has a FollowSymLinks option or something that may or may not be enabled.
But illustrated above is my favorite option #1 - no question.
You'll see it even has Drupal in a subdir. That was not strictly neccessary ... but feels better.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
Note- the subdomains printed here are just placeholders that are actually falling back to 'default' so clicking won't be too enlightening. I have other working ones I didn't list in the screenshot, and yes, clean-urls is totally normal under them.
Thanks - now Drupal Core .htaccess
Thanks for the advice and screen shot, that's made it a whole lot clearer. I've done away with .htaccess files redirecting to Drupal core and gone with the above Virtual Host thing. I've now got Clean Url's working with my sub-domain.
Next question. I'm now fiddling with the www thing, wanting to enforce only non www. Am I right that I only alter the .htaccess file that resides in the Drupal Core directory. This is a snippet from the Drupal Core .htaccess.
# To redirect all users to access the site WITHOUT the 'www.' prefix,# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
If I have 5 different accounts, do I merely copy the above 5 times substituting for the correct accounts.
Once again, you've made things heaps easier.
___________________________
Steven Taylor
Melbourne, Australia.
http://superjacent.net/cms
copy & paste is always a
copy & paste is always a warning flag.
I'm sure there is a slightly better pattern you can come up with in the rewrite that will wildcard your domain in the replacement rule.
Play with that. mod_rewrite is deep magic, but when you get it you'll have earned a beer.
You want me to do it for you ... it'll cost more than a beer ;-)
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
VB or Fosters
So at least I'm on the right track.
I've bookmarked a few Apache RewriteRules type sites and scribbled down four pages of notes. So even though I'm no longer going with the .htaccess redirect method it's been time well spent from a learning point of view. I'll see if I can nut out a pattern matching routine to account for all my sites.
Once again, thanks.
___________________________
Steven Taylor
Melbourne, Australia.
http://superjacent.net/cms
Last words ...
Enable the RewriteLog in Apache for a while, or you'll be working blind. It's way scary informative when getting to grips with the arcane-ness.
Oh, that won't really be possible on most shared hosts - it's more of a local dev site thing.
Ah well, just an idea.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
If you have a dedicated IP
If you have a dedicated IP address at your new host, access your site on your new host via IP address.
If you do not, I would set the site up locally and implement the changes. Once done move your local site to new host and repoint your domain.
I usually use .dev instead of .com for my local sites. Most of your urls should be relative so it shouldn't matter if your site ends in .dev instead of .com. For situations where the TLD is important, I do edit the HOST file so that it has the actual domain name too but I always make sure that I comment it out when done. This approach keeps me from being confused.
Subscribed
Subscribed
Thank you for your tips
Hi pulsifier,
I tried your methods on five separate occasions and it was a few hours ago that i got it to work.
I did not know why it works now and not before, but it works.
Thanks.
....
I am writing this so that others may consider that if they cannot get it to work, it is possibly something else other than the code.
That's about the extent of my knowledge. Cheers.
Why is this happening at the instalation stage?
It seems to me that the problem here started at the installation stage. I just installed Drupal 6 by way of ftping the .gz file to my server under public_html folder. The installation extracted drupal under a new folder called "drupal-6.1/?" now in order in access my site I need to go to www.mysite.com/drupal-6.1?
Now can someone please help me figure out how to install drupal-6.1.tar.gz in a way that the site will be located under public_html and not in its own sub-folder?
Thanks,
"I get by with a little help from my friends"
Virtual Hosts
From within this thread - check this entry http://drupal.org/node/144643#comment-776336 and replies that follow. From your control panel or whatever it's called that you use to administer your site, simply point your domain to that sub-folder (drupal-6.1). Look for settings relating to Virtual Hosts or Document Root. After changing, you'll have to wait a few hours for the effect to take place. After it's done you will not have 'drupal-6.1' in your url.
I'm assuming that you use cpanel and that's not what I use so can't elaborate any further, which links to click etc.
___________________________
Steven Taylor
Melbourne, Australia.
http://superjacent.net/cms
it's how it goes,
It's normal practice for application packages to unpack into an identifiable subdirectory. Not doing so is possible, but referred to as a 'tarbomb' as it can unexpectedly shower unknown files all over the place when unpacked uncautiously.
Most folk who can find their way around a file system can then inspect the files and place the distribution where it's needed.
Often, the unzip facility you use can give you the choice. What command did you use to unzip it?
For you now, you need to find out how to "move" the files in that subdirectory into the place you want them. That's up to your control panel, or your FTP or shell access.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
Drupal installed in subdirectory but made to appear in root
It worked for me too. Thank you so much, and to pulsiter for starting the thread off.
I was having awful trouble debugging RewriteRules on a machine without access to the rewrite log, till I blindly copied this.
This has worked perfectly
This has worked perfectly for me thanks!
Re-directs in godaddy
Pulsifer,
I use godaddy as my host and they do not allow redirects off the root directory for their basic hosting plans. Thank you for your tip on using the .htaccess file to accomplish this task. The tip, plus a couple of hours going over apache documentation saved me some money.
Tony
Drupal still visible in gallery urls
I've read through the entire thread and got it partially working. Here's what I have:
/httpdocs/oldsite/static.html
/httpdocs/drupal/
/httpdocs/drupal/gallery2/
Clean URLs and Gallery module enabled.
What I want is (a) make drupal appear as root and (b) add a bunch of redirects for the static site (i.e. /oldsite/somefile.html -> /drupal/node/X).
I've used the above configuration suggestions and came up with the rules below[1] (www.drupal.development is my local test site).
This works for all drupal urls, but not for the gallery part. All gallery urls show '/drupal/' in the url.
Also, if I enter a url with '/drupal/' in it, the correct page displays, but the '/drupal/' part remains in sight.
Finally, where do I put the static site redirects? Before the drupal manipulation code, in between somewhere or after?
update: the static redirects below all drupal related redirects work fine. They look like:
RewriteRule ^/?oldsite/some.html$ /node-name [R]
update: I haven't updated /drupal/.htaccess nor set the baseurl in sites/default/settings.php
[1] /.htaccess
# Check for /drupal-based URLs and remove /drupal
RewriteCond %{HTTP_HOST} !^www\.drupal\.development$ [NC]
RewriteRule ^/?drupal/(.*) http://www.drupal.development/$1 [R=301,L]
# Make drupal the home page
RewriteRule ^$ drupal/index.php [L]
# If an actual file exists in the drupal dir, prefer it
RewriteCond %{DOCUMENT_ROOT}/drupal%{REQUEST_URI} -f
RewriteRule .* drupal/$0 [L]
# Otherwise change behind-the-scenes URL to drupal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal/index.php?q=$0 [QSA]
#Old pages are redirected to new nodes
RewriteRule ^/?oldsite/some\.html$ /content/newnode [R]
RewriteRule ^/?oldsite/other\.html$ /node/123 [R]
Thanks.
I am still having problems , someone please help me
I am using godaddy as my hosting and I installed drupal in a subdomain that points to the root of that folder where drupal 6 is installed for that aliased subdomain.
Please help.
Can't get Clean Urls to work at all.
Should I have installed it as a subdirectory?
I don't understand exactly
I don't understand exactly how your site is set up, but I am not sure that you need any of the above. Can you explain your setup with an example?
Do you have a subdomain http://sub.example.com where you want to run Drupal?
Does that subdomain leads to a public_html/sub directory?
Do you have Drupal installed in the public_html/sub directory?
Have you uploaded Drupal's .htaccess file included in the tar.gz package?
If everything is as a described, try this: Edit Drupal's .htaccess file, find the line
# RewriteBase /and remove the front#.HTTPD.CONF solution
I had a hard time getting this to work. I could get the initial drupal page to load at www.mysite.com, but any subsequent link returned a drupal/ in the path and led to a non-existent page. I could manually remove the drupal/ from the url path and the page would load.
I subsequently found this thread. Before implementing this .htaccess coding, I contacted my service provider, WestHost, who suggested that I edit the httpd.conf file by changing the DocumentRoot and Directory settings to the directory I wanted. It worked! And clean urls are working fine.
For those who don't know (like me) the httpd.conf file was located in the etc/httpd/conf directory on my server. Now even though drupal is in a subdirectory, the base url points directly to that directory as the root.
That was the right thing to
That was the right thing to do. The complicated .htaccess techniques discussed in this thread are a bit fragile and are intended for the poor souls on shared host who can't point a domain to the directory they want in any other way.
Even on a shared host, if the cpanel allows pointing a domain to the directory you want, that is a more solid way than these techniques.
Original Poster's Method Seems to work for me today!
I tried another method which was apparently incomplete to do the same deal as the original poster. So, since the other wasn't 100% complete, I figured I'd give this one a try. It worked like a charm. No issues so far.
By the way, I'm using anhosting/midphase for hosting of the quoted site. I suppose if I end up setting up any more sites underneath the same directory, I'll need to add them into the root .htaccess file. That won't be a big deal, I'm sure.
If anyone else here uses anhosting/midphase, and knows a way to do this with shared hosting there other than using the .htaccess file, it'd be great if you could point me down the correct path to do so. :0)
Regardless, it's working, and I'm happy.
Update.php
When I tried to update the DB script at http://example.com/update.php, it gave me error: "Page not found."
The solution: Add this line to .htaccess
RewriteRule ^update\.php$ /drupal/update.php [L]Subscribing!!
Subscribing!!!
You all seem smart enough
Ok, you all seem smart enough to solve my problem. Any help you can offer would be much appreciated!!!!
I installed Drupal in a sub directory on my website to use as a Blog. http://www.danfinney.com/blog/
Everything is running and working well. I submitted the XML feed url to Google Webmaster tools as a Sitemap. Google successfully downloaded the feed but tossed the following warning:
URLs not followed
When we tested a sample of URLs from your Sitemap, we found that some URLs redirect to other locations. We recommend that your Sitemap contain URLs that point to the final destination (the redirect target) instead of redirecting to another URL.
HTTP Error: 301 (Moved permanently)
URL: http://www.danfinney.com/blog
I did some investigating and figured out what the problem was. The feed url http://www.danfinney.com/blog/rss.xml is indicating the base path of the site without the trailing slash:
alternateURL="http://www.danfinney.com/blog"
base href="http://www.danfinney.com/blog"
When you go to: http://www.danfinney.com/blog it redirects you to include the trailing slash: http://www.danfinney.com/blog/
I am using the Global Redirect module, but the "remove trailing slash" feature does not seem to work on the main directory.
I also tried to edit settings.php so that the feed would include the trailing slash in the urls, but my attempts were not successful, as you are not allowed to add a trailing slash to the base url.
I either need to change the base path to include the trailing slash, or I need the trailing slash removed. Can someone point me in the right direction?
.htaccess?
Perhaps you can make the necessary changes in the .htaccess file? I'm not 100% sure myself, as I've only messed with that portion of things enough to get things done on an as needed basis on my own sites so far.
Otherwise, there are other modules that might help. For instance, I think there is one that is either in progress, or already available for the Google Sitemap or XML SiteMap idea. Try searching around the modules section of this site, or either over at www.drupalmodules.com for info.
Not to mention one other that worked really well for me the other week. The Path Redirect module worked wonders for a different situation of mine, but it might help just the same for this situation. I realize it wouldn't be the best case scenerio, in that you probably want to make sure it's fixed without extra code, but if it works, the site visitors won't care how it's fixed. ;0)
a simple way that works with clean urls - two steps
Here is what I did. I only have 1 site and no subdomains so I did not test this with them. I DO have other non-Drupal applications being served out of the same root, like this...
public_html/drupal/
public_html/foo/
public_html/bar/
In public_html/.htaccess:
Options -Indexes
RewriteEngine On
RewriteRule ^$ drupal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ drupal/$1
In public_html/drupal/sites/default/settings.php:
$base_url = 'http://www.mysite.com';Apache MUST have read+execute permissions on the public_html directory for it to work, othwise you get many access denied errors.
Trailing Slash Subdirectory
John,
These instructions do work for removing the subdirectory. So in your case you would have mysite.com/drupal/postname and with your rewrite it would come out as mysite.com/postname
What I am trying to accomplish is to leave the "drupal" directory but remove the trailing slash.
Right now the Stories act this way, so mysite.com/drupal/postname/ becomes mysite.com/drupal/postname But what I am trying to accomplish is to have mysite.com/drupal/ become mysite.com/drupal
Can you lend a hand?
It worked fine for me. Thanks!
I have the same sort of situation as you describe, John, so I tried your simplified approach and it's working just fine for me so far. I did not have the option of changing the Document Root with my hosting situation. Thank you, sir!
I too need to change the url
I too need to change the url to just www.mysite.com. But before I totally screw up my site, I"m going to ask stupid noobie question. Do I just cut and past the exact code above and overwrite what is currently in the root .htaccess file?
Here is a copy of my code:
# Hostmonster.com
# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)mysite.com$
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/drupal/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you will use for your main domain.
RewriteRule ^(.*)$ /mysite.com/drupal/$1
# Change yourdomain.com to be your main domain again.
# Change 'subfolder' to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)mysite.com$
RewriteRule ^(/)?$ drupal/index.php [L]
Problem after uncommenting in settings.php
I went ahead and made one change to the core .htaccess file above to:
RewriteRule ^(.*)$ /mysite.com/$1
I the changed to IfModule XXXmod_rewrite.c>
But when I change the settings.php file by uncommenting the line # $base_url = "http://www.mysite.com'; I lose most of the style sheet formatting and access to all the nodes.
Any ideas?
Dorys