homepage Welcome to WebmasterWorld Guest from 23.23.57.182
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
.htaccess and double domain
need help with this... anyone?
johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 3:25 pm on Oct 2, 2009 (gmt 0)

Hi. Here's what I am trying to do. I have a folder inside my hosting account that is used by a second domain. So...

mydomain.com (first site)
mydomain.com/site/ (second site) (connected to: my2domain.com)

Now I would like that everytime someone access that folder or any content inside that, from mydomain.com, it will be redirected to a 404 Not Available Page.

So that folder will only be visible when accessing the my2domain.com that is connected to that folder, sharing one hosting account with mydomain.com

Here is what I done.
I have this .htaccess inside the /site/ folder:

rewriteengine on
rewritecond %{HTTP_HOST} ^www.mydomain.com$ [OR]
rewritecond %{HTTP_HOST} ^mydomain.com$
rewriterule ^$ "http\:\/\/mydomain\.com\/site/404/404.html" [R=301,L]

This redirect every one who is trying to visit mydomain.com/site to an 404 html page. But the problem is, that if you trying to direct link an image like:

mydomain.com/site/image.jpg (or)
mydomain.com/site/index.html

it shows the second site! So I need that every files accessed this way will redirect the user to a 404 error page.

So the site inside that folder will only be available from the second domain.

:) Hope you know what I mean.
Thanks in advance.

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3999977 posted 10:00 pm on Oct 2, 2009 (gmt 0)

> So I need that every files accessed this way will redirect the user to a 404 error page.

That's really not a good approach. I'd suggest that you simply 'fix' the URL and redirect the request:

In example.com/site/.htaccess :

RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /site/[^\ ]*\ HTTP/
RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]

This takes (only) direct client requests for 'pages' in the /site folder, and redirects them back to the same 'page,' but on site.com.

The extra complication of checking THE_REQUEST is needed to prevent an 'infinite' loop caused by a conflict that would otherwise occur between this rule and the mechanism used to map site.com URLs to your /site folder.

Note several corrections to anchoring and escaped characters (regular expressions tokens need only be escaped in regex patterns as shown), and the single RewriteCond testing both the www and non-www hostnames.

Jim

johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 11:19 pm on Oct 2, 2009 (gmt 0)

To let you better understand what I am trying to do. I want to give the "illusion" that the second domain (who has a shared hosting with the first domain) isn't in anyway linked to the first domain.

Now... for example let's have:

www.doggie.com
www.kate.com

Where kate.com is sharing the hosting of doggie.com using a folder (and not a separate webspace).

Now if someone is "too curious" and type in...

www.doggie.com/site/index.html

He will discover that kate.com is... sharing a host with doggie.com :/ so all I want to do is that...

everytime doggie.com try to access every file (index.html etc.) or even the folder that is using kate.com it will redirect to a 404 not available page...

but... if kate.com is accessing it's own folder on doggie.com/site/ it will show kate site. LoL.

Pretty confusing. :)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3999977 posted 11:28 pm on Oct 2, 2009 (gmt 0)

example.com is your main domain, and 'site' is the second domain, to be consistent with the 'site' subdirectory.

Jim

johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 10:16 am on Oct 3, 2009 (gmt 0)

Hi Jim. I just tried this way too. But when I type http://example.com/site/index.html or
http://example.com/site/

The site is still visible :/
I've a host on godaddy btw, maybe this could help.

jd01

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3999977 posted 2:30 pm on Oct 3, 2009 (gmt 0)

Did you empty your browser cache? I can't see any issue at all with jdMorgan's ruleset and I've been staring at it for about 10 mins and he's usually right...

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3999977 posted 4:14 pm on Oct 3, 2009 (gmt 0)

Only "usually" -- I'm devastated... :(

See if flushing the cache helps. If not, please go over your posts above, and be sure that all details are correct. The code is trivial and should work just fine, as it does on hundreds of other sites.

Jim

jd01

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3999977 posted 4:21 pm on Oct 3, 2009 (gmt 0)

My Apologies Mr. Morgan, Sir,

Allow me to 'enhance' my preceding post...

Did you empty your browser cache? I can't see any issue at all with jdMorgan's ruleset and I've been staring at it for about 10 mins and he's usually* right...

* When using the word 'usually' in conjunction with jdMorgan being right, I mean: I think out of all the posts of his I've read (probably well over 1000) there have been possibly two occasions where he had a little tiny error in one rule, which was probably a typo that slipped by his review... (IOW: It's very, highly, extremely likely your browser cache & the reason I stared at it so long is because if an error slipped by him it could very easily slip by me too, because if he makes one it's little, tiny and could easily go unnoticed, even by a trained eye.)

[edited by: jd01 at 4:28 pm (utc) on Oct. 3, 2009]

johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 4:26 pm on Oct 3, 2009 (gmt 0)

Hi. Yep I do always empty the cache... but I will give you a second try... don't be devastated at all :D I'll update this post asap.

johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 4:34 pm on Oct 3, 2009 (gmt 0)

My apologies too Mr. Morgan.
It was my fault as I used for the [site.com...] - the second domain address... so it was redirecting to the second page instead of a 404 error page. Now I replaced it with the correct link to the 404.html page and everything is working.

Don't be devastated anymore. :D
TY btw :)

jd01

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3999977 posted 4:34 pm on Oct 3, 2009 (gmt 0)

? Why are you redirecting to an error page...
As jdMorgan was saying, take people to the site.

IWO: Change it back to what it was when it was 'not working' just a little bit ago. There's no reason I can think of to not take people to the information they were looking for... It's not a duplicate or anything any more, you're just taking them from where it used to be to where it is now.

If you really don't want them to see it, there's not point in redirecting, just serve them a Gone error, but like jdMorgan said, that's really not the best idea.

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3999977 posted 5:05 pm on Oct 3, 2009 (gmt 0)

Yes the purpose of the code I posted above is to redirect client requests for the sub-folder URL (the "wrong" URL) back to the "correct" subdomain URL. This avoids losing/confusing visitors, prevents search engines from indexing the "wrong" URL, and forces them to correct that "wrong" URL in their indexes if they have already listed it. This is the correct solution in accordance with HTTP conventions and specifications, and you'll deviate from it at your own risk...

Actually redirecting to a 404 error page is almost "suicidal" if you value your search rankings.

Jim

johnnyDoe

5+ Year Member



 
Msg#: 3999977 posted 7:18 pm on Oct 3, 2009 (gmt 0)

I've got those folders in disallow inside the robots.txt, so it's ok. But google will still index them cause they're directly connected to a second domain as a hosting. (and not redirect)

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3999977 posted 7:47 pm on Oct 3, 2009 (gmt 0)

Well, it's not OK, but I've said all I can.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved