Your .htaccess genius is needed! =D

Merlin

Expert Member
Joined
Jan 18, 2006
Messages
2,798
Reaction score
324
Location
Cape Town, South Africa
.htaccess - redirect exclusions (SORTED!)

Hi all,

I finally got my 'site up and running the .htaccess that I wanted - but now I'm also hosting a friend's domain.

I've gotten all of that working...

Here is my original .htaccess

RewriteCond $1 !^phpinfo\.php$
RewriteCond $1 !^robots\.txt$
RewriteRule (.*) http://mydomain.com/sample/$1 [R,L]

That redirect all requests to the 'sample' folder, EXCEPT for phpinfo.php and robots.txt

The problem is that is now also requesting www.friendsdomain.com to the 'sample' folder.

I've put some temp' instructions in place to get it working for the moment but I specifically want to use the code above if possible.

How do I a domain exclusion to that code, please?

Thanks, Nic
 
Last edited:
Hi DS,

Thanks for the reply.

Code:
RewriteCond $1 !^phpinfo\.php$
RewriteCond $1 !^robots\.txt$

RewriteCond %{HTTP_HOST} !^www.friendsdomain.com

RewriteRule (.*) http://mydomain.com/sample/$1 [R,L]

Is that ^^^ what you had in mind?

friendsdomain and the two pages must NOT be redirected. Everything else should go to /sample/
 
Yes, have you tried that? I'm not really sure what your setup is: do you have both your domain and your friend's domain pointing to the same web account?
 
Hi DS,

Yup, both domains are pointing to my hosting account.

Mine is the primary domain and hers is an 'addon'.

I've just tried your code - no luck. Still forwards friendsdomain.com to /sample/

Any other ideas?

Thanks, Nic

PS: Thanks for the guides. :)
 
For me to really test it I would need you to provide me with your real domain name, friend's domain name and possibly FTP access. I don't have 2 domains pointing to any of my web accounts so I'm unable to test this out my side. Understandably this is a big risk but if you feel comfortable feel free to PM me the details.
 
Hi DS,

To be honest, I'm not that keen to dish out my FTP details (sorry), and seeing as how it's the root that you need access to, I'm not really able to sort out a temporary account either. :s

However, my domain is the3rdrock.com and my friend's is exquisiteinteriors.co.za

Thanks.
 
Hi DS,

I've disabled my original .htaccess code (the one disallowing the specific pages) and instead put in two redirects. One for the3rdrock and one for exquisiteinteriors.

I want to integrate an exclusion for an entire domain (exquisiteinteriors) into my original code.

Example:

Code:
# Root redirect exclusions
RewriteCond $1 !^phpinfo\.php$
RewriteCond $1 !^robots\.txt$

# THIS IS WHERE I NEED TO EXCLUDE exquisiteinteriors.co.za

# Main 'site redirect
RewriteRule (.*) http://the3rdrock.com/mongolrally/$1 [R,L]
 
I GOT IT!

Code:
# Root redirect exclusions
# Domain exclusions
RewriteCond %{HTTP_HOST} ^(www\.)?exquisiteinteriors.co.za$
RewriteRule .* - [S=3] 

# Page exclusions
RewriteCond $1 !^phpinfo\.php$
RewriteCond $1 !^robots\.txt$

# 'Mongol Rally' root redirect
RewriteRule (.*) http://the3rdrock.com/mongolrally/$1 [R,L]

First we specify which domain is to be excluded from the general redirect: (www.)exquisiteinteriors.co.za

Then we specify that if EI is the domain in question, then we need to skip the next 3 steps.

Then specify which pages in the root should be excluded: phpinfo and robots

Now we can assume all is well and redirect everything else to the primary domain's subfolder.

et Voila!

I am seriously chuffed with myself right now. ;)

...now to tackle the addon domain quirks. Haha.
 
Last edited:
*lol!*

When I load her 'site on my local XAMPP installation it redirects to my 'site online. Hahahahahahaha!

Online it works perfectly.

WtF.
 
Doh! I've just realized that I had my 'in progress' .htaccess stored in there. *lol*

Thanks for pointing out my stupidity. :)

Related - is there a way to get .htaccess to work with XAMPP?
 
I would image removing the comment ('#') from the line:

#LoadModule rewrite_module modules/mod_rewrite.so

in the httpd.conf should work once it knows to load that module.

Restart Apache afterwards.
 
Top
Sign up to the MyBroadband newsletter
X