domain.com/folder to www.domain.com/folder/

Using a single web hosting account to host multiple sites

domain.com/folder to www.domain.com/folder/

Postby joshocb » Fri Dec 07, 2007 6:55 am

hello,

I'm having trouble forcing www with subfolders. I have the rule setup and working in the web root but it seems to ignore this for any subfolder with its own .htaccess. This is the case even if the subfolder's .htaccess has only
Code: Select all
RewriteEngine on



the rule i used is

Code: Select all
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/folder/$1 [L,R=301]


not only do subfolders ignore it they in fact revert to domain.com/folder if www.domain.com/folder is requested.

I've tried the same rule in the sub folder as in the web root with the sub folder appended but this still causes problems. In fact if I go to domain.com/folder to redirects to www.domain.com/folder//server/user/public_html/folder with the server path.

Any insight would be much appreciated

Thanks[/code]
joshocb
 
Posts: 4
Joined: Fri Dec 07, 2007 6:47 am

Postby richardk » Fri Dec 07, 2007 1:28 pm

This should work anywhere
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


Or you can try
Code: Select all
RewriteOptions inherit

in .htaccess files in sub directories.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby joshocb » Mon Dec 10, 2007 3:47 am

Thank you for your response. Adding the REQUEST_URI and the RewriteOptions inherit seems to have doe the trick! you're a star. :D
joshocb
 
Posts: 4
Joined: Fri Dec 07, 2007 6:47 am

Postby joshocb » Mon Dec 10, 2007 4:25 am

I have discovered one issue. My password protected directories forward straight to a 401 error. Is there a way round this?

Thanks
joshocb
 
Posts: 4
Joined: Fri Dec 07, 2007 6:47 am

Postby richardk » Mon Dec 10, 2007 9:31 am

Adding the REQUEST_URI and the RewriteOptions inherit seems to have doe the trick!

You shouldn't need both.

My password protected directories forward straight to a 401 error.

What (relevant) .htaccess files do you have? What is in them?

You can try adding
Code: Select all
RewriteEngine Off

with the HTTP Auth code.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby joshocb » Tue Dec 11, 2007 2:21 am

Thanks again for your response. I have a read through the forum and found some php that I've put in a custom 401 error page:

Code: Select all
$uri = explode('?', getenv('REQUEST_URI'), 2);
if(substr($uri[0], -1, 1) != '/' &&  strpos($uri[0], '.') === false)
{
  header('Location: http://' . getenv('HTTP_HOST') . $uri[0] . '/' . $uri[1], true, 301);
  exit();
}
$uri = $uri[0];
if(!isset($_GET['page']) || empty($_GET['page']))
{
  $_GET['page'] = trim($uri, "\n\t /");
}
unset($uri);


This fixes the password problem and all seems to be working now.

Thanks again!
joshocb
 
Posts: 4
Joined: Fri Dec 07, 2007 6:47 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 27 guests

cron