Redirect for document root but not child folders

Using a single web hosting account to host multiple sites

Redirect for document root but not child folders

Postby paulcobb » Mon Dec 15, 2008 8:56 am

I have a redirect set up for the root directory of my host.
www.myusername.myhost.co.uk goes to www.myfirstwebsite.co.uk

I then have a number of domains (www.mysecondwebsite.co.uk www.mythirdwebsite.co.uk etc)which point to folders within my root directory (htdocs) and where the data for these sites reside.
I wish to allow these to operate as they are currently (no redirect) with only the root directly redirected.

The Rewrite_Cond(s) needed has me stumped at the moment.
Any help would be welcomed.

Paul
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Postby richardk » Mon Dec 15, 2008 9:15 am

What is your current mod_rewrite?

You only want myusername.myhost.co.uk to redirect to www.example.co.uk and nothing else? Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?myusername\.myhost\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [QSA,L]


If you want example.co.uk to redirect to www.example.co.uk as well, replace
Code: Select all
^(www\.)?myusername\.myhost\.co\.uk$

with
Code: Select all
^((www\.)?myusername\.myhost\.co\.uk|example\.co\.uk)$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby paulcobb » Mon Dec 15, 2008 10:06 am

The file I had been testing was for the initial redirect of www.username.myhost.co.uk to www.mywebsite.co.uk

I could not get this to work until my host suggested this solution

RewriteEngine On
RewriteRule .* http://www.mywebsite.co.uk/ [R=301,L]

This does work in the document root, but obviously redirects everthing.
I could not get the RewriteRule to work with (.*)
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Postby richardk » Mon Dec 15, 2008 10:09 am

Then try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?myusername\.myhost\.co\.uk$ [NC]
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby paulcobb » Mon Dec 15, 2008 10:16 am

I just a 500 server error with this
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Postby richardk » Mon Dec 15, 2008 10:21 am

What does your error log say the error is?

Try removing
Code: Select all
Options +FollowSymLinks
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby paulcobb » Mon Dec 15, 2008 10:27 am

I don't have access to the error log I'm afraid.

After removing the first line, the result is like deleting the .htaccess file. All works as before.
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Postby richardk » Mon Dec 15, 2008 10:33 am

Does this mod_rewrite test work?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?myusername\.myhost\.co\.uk$ [NC]
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [R=301,L]

and
Code: Select all
RewriteEngine On

RewriteCond %{HTTP_HOST} myusername\.myhost\.co\.uk [NC]
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby paulcobb » Mon Dec 15, 2008 10:42 am

Mod_rewrite test gives 500 error, as does code sample 1. Code sample 2 has not effect (as if no .htaccess file).
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Postby paulcobb » Mon Dec 15, 2008 10:59 am

Just looking at the google test code again.
If I remove line 1 this works ok.
Not sure what that tells you?
paulcobb
 
Posts: 9
Joined: Mon Dec 15, 2008 8:43 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 15 guests

cron