Forum Moderators: phranque
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.
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]
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
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. :)
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]
Don't be devastated anymore. :D
TY btw :)
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.
Actually redirecting to a 404 error page is almost "suicidal" if you value your search rankings.
Jim