cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess redirect to ccgi server folder

steven
Newbie
Posts: 7
Registered: ‎04-09-2007

.htaccess redirect to ccgi server folder

Hi everyone,
I'm trying to use our webspace on the ccgi server to host two different websites: http://www.domain1.co.uk and http://www.domain2.co.uk. I've  had http://www.domain1.co.uk on the ccgi server for a while and recently registered http://www.domain2.co.uk. With some help from F9 support, the DNS records for both domains now point to the ccgi server. I've followed the suggestions on the PlusNet forum (http://portal.plus.net/central/forums/viewtopic.php?t=52576) to try using a .htaccess file to redirect requests to www.domain2.co.uk to a subfolder in the ccgi webspace but can't get this going at all. I don't get any errors at all - going to http://www.domain2.co.uk simply directs me to the http://www.domain1.co.uk site in the root space of the ccgi folder. It's as if the .htaccess file isn't even being accessed.
My .htaccess file looks like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain2.co.uk$ [nc]
RewriteRule (.*) /domain2/$1

Am I missing something here?
Thanks.
11 REPLIES 11
ffupi
Grafter
Posts: 370
Registered: ‎01-08-2007

Re: .htaccess redirect to ccgi server folder

It should work.
And it works on my ccgi to have two different domains pointing to two different directories.
I understand, both domains point to ccgi, and all the Domain control settings have been made as outlined in the referenced threat in the old PN-forum.
You want http://www.domain1.co.uk to point to the directory1, which is directly in root of ccgi.
And http://www.domain2.co.uk shall similarly point to the directory2.

Your .htaccess file in root of ccgi should contain the following lines:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain1.co.uk$ [nc]
RewriteRule (.*) /directory1/$1
RewriteCond %{HTTP_HOST} ^www.domain2.co.uk$ [nc]
RewriteRule (.*) /directory2/$1


In case also the http://domain1.co.uk and http://domain2.co.uk shall point to these folders .htaccess in root should contain these lines instead (old forum entry: http://portal.plus.net/central/forums/viewtopic.php?t=52831):
RewriteEngine on
# domain1.co.uk to point to www.domain1.co.uk
RewriteCond %{HTTP_HOST} ^domain1.co.uk$ [nc]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]
# www.domain1.co.uk to point to directory1
RewriteCond %{HTTP_HOST} ^www.domain1.co.uk$ [nc]
RewriteRule (.*) /directory1/$1
# ------------------------------------------------------------
# domain2.co.uk to point to www.domain2.co.uk
RewriteCond %{HTTP_HOST} ^domain2.co.uk$ [nc]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]
# www.domain2.co.uk to point to directory2
RewriteCond %{HTTP_HOST} ^www.domain2.co.uk$ [nc]
RewriteRule (.*) /directory2/$1


This works with me. I am sure it can be refined or changed to whatever settings you prefer.

Remark to the Domain control settings, these can be a bit different as well to what I wrote in the old forum. Someone from PlusNet changed it to:
Quote from: ffupi
Found that somebody changed the entries of my first domain to:
Left field        Type    Pri    Right field
domain.tld.a84.92.1.4
wwwa84.92.1.4
mx20mx.last.plus.net.

And it still works.
Okey, so I did this now with the new domain as well.
(Slightly edited)
And it works as well to point both the domain.tld and the www.domain.tld to root of ccgi. No clue what difference this makes on the net?
steven
Newbie
Posts: 7
Registered: ‎04-09-2007

Re: .htaccess redirect to ccgi server folder

Hi ffupi and thanks for the response.
I've tried both your code samples and have made a copy of the site hosted in the ccgi root folder into a sub folder on the ccgi server but neither code samples seem to do anything.
The domain records seem fine as going to to both domains with or without the "www." at the start takes me to the same site each time.
I'm not familiar with .htaccess files, does anyone know a way of testing that the code in the file is being executed?
ffupi
Grafter
Posts: 370
Registered: ‎01-08-2007

Re: .htaccess redirect to ccgi server folder

.htaccess works instantaneously.
Did you clear the cache in your browser? Press F5. Then surf again to domain1 and domain2.
steven
Newbie
Posts: 7
Registered: ‎04-09-2007

Re: .htaccess redirect to ccgi server folder

Yes, I'm clearing the cache after each change and still no joy.
What I have noticed is that some content (images and output from some javascript) is missing when I have an .htaccess file with the rewrite code in it. If I then upload a blank .htaccess file in its place, the site displays properly. I don't know if that's significant or not?
ffupi
Grafter
Posts: 370
Registered: ‎01-08-2007

Re: .htaccess redirect to ccgi server folder

Hello
It took me several week as DIY to find the .htaccess code. It directs two domains into two subdirectories on ccgi-root. Any index.htm or index.php file in these subdirectories will display properly. I am using Joomla 1.5 and TYPO3 4.0 as two different cms in each subdirectory and there is no problems - all works fine.
I am not able to change the .htaccess for specific problems, and I am very unhappy that I did not find how to direct into a sub-subdirectory.
For to analyse your problem you would need to send me the domain names (private message e.g.). However, javascript etc. - no clue.
It could be that the original DNS is frame-wrapped by wherever it is registered and forwarded to PlusNet who then forwards to ccgi. This does not work, it needs to be a DNS redirect from the registration company.
Another possibility is, that the javascript searches things elsewhere but not in the subdirectory?
It could also be that the chmods are not set correctly, chmod=755 is always recommended by the BrightSparks.

You could e.g. rename the two subdirectories (for to keep safe for the time being), and create a new directory1 and directory2. Then put different index-files into directory1 and 2. Should the redirect then work and index file 1 and 2 show up on browsing to domain1.co.uk and domain2.co.uk, then it would be clear that the problem were elsewhere.

Does actually http://ccgi.username.plus.com/directory1 and http://ccgi.username.plus.com/directory2 work properly. This way it can always be checked if it would work without the DNS-.htaccess redirect of the domains.

Hope there is a clue for you what it could be?Huh
steven
Newbie
Posts: 7
Registered: ‎04-09-2007

Re: .htaccess redirect to ccgi server folder

Hi Again,
Thanks for all your help with this - I didn't expect this to be so difficult to achieve!
I tried taking out the two sites and just creating two test folders: test1 and test2 with a simple index.html file in each one. I then added in an .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain1.co.uk$ [nc]
RewriteRule (.*) /test1/$1
RewriteCond %{HTTP_HOST} ^www.domain2.co.uk$ [nc]
RewriteRule (.*) /test2/$1

Trying to access either domain name I get a "500 Internal server error" error message. Trying to access the index.html files directly e.g. www.domain1.co.uk/test1/index.html I get the same "500 internal server error".
If I remove the code from the .htaccess file I can then access www.domain1.co.uk/test1/index.html succesfully.
Huh
To answer your other questions, the domain were registered through Force9 and I can access the sites by going to http://ccgi.username.force9.co.uk/folder1/, etc...
I'm not too concerned with the missing javascript and images, it just seems that everytime I try and place some code in the .htaccess file it screws up the site!
Thanks again.
ffupi
Grafter
Posts: 370
Registered: ‎01-08-2007

Re: .htaccess redirect to ccgi server folder

The .htaccess-file is definetely OK. I double checked it letter for letter with mine.
When this .htaccess is resident in root, can you then access http://ccgi.username.force9.co.uk/folder1/index.html and
http://ccgi.username.force9.co.uk/folder2/index.html ?
Then hidden question is, did you set the index.html to chmod=750 (or 755)? Error 500 has something to do with inaccessibilty of a file due to incorrect chmod settings. Has nothing to do with .htaccess.
Promise, it will work!
steven
Newbie
Posts: 7
Registered: ‎04-09-2007

Re: .htaccess redirect to ccgi server folder

Yes, file rights are set to 755 and I can access the two index files as you've suggested.
I'm going to abandon this for now as I really need to get the site going. So I'm going to make some changes and go back to using the standard webspace for the second website for now.
Thanks very much for taking the time to help out Smiley
ffupi
Grafter
Posts: 370
Registered: ‎01-08-2007

Re: .htaccess redirect to ccgi server folder

OK.
That you can access the files correctly with
http://ccgi.username.force9.co.uk/folder1/index.html and
http://ccgi.username.force9.co.uk/folder2/index.html
shows that there is no chmod problem or else.
However, as .htaccess is correct I do not understand why you should not be able to access with
e.g. www.domain1.co.uk/index.thml and
e.g. www.domain2.co.uk/index.html .
This does not make sense. Huh
It would mean that there is a cgi-error which does not allow .htaccess to work, I would rise a ticket.
Another thing I have not thought about: are there other .htaccess files in the subdirectories domain1 and/or domain2 ? These need of course to be adapted acording to whatever cms you use. In my case I needed to change the folder base/ or something for Joomla.
If you'd like give me the URLs per private message and I will surf to them and tell you what I think.
MikeWhitehead
Grafter
Posts: 748
Registered: ‎19-08-2007

Re: .htaccess redirect to ccgi server folder

I don't know if this will be any use to you but:
http://aarronwalter.com/2007/01/15/running-two-domains-on-one-shared-hosting-server/
I'm not a big user of htaccess so don't know the ins and outs very well. Hope this helps Smiley
steven
Newbie
Posts: 7
Registered: ‎04-09-2007

Re: .htaccess redirect to ccgi server folder

Thanks for the feedback guys. I've only got one .htaccess on the server and I get the same problem with that example from the link Mike posted as well, where the redirect doesn't work and some of the content on my site is missing. I've gone back to having the two sites hosted on the two web servers in the meantime.
If I need to move the site back onto the ccgi server I'll try and get support involved again but they actually suggested I try this forum for help when I initially asked about .htaccess files.