Forum Moderators: phranque
I have a CMS installed that can publish to multiple sites - however I'm not on a dedicated server so root access is not possible.
My host suggests I use "a rewrite rule within a .htaccess file to create the redirect from the package where the domain name is currently hosted"
So that site where the database is hosted - example.com/siteb can be accessed by siteb.com.
Is that possible in .htaccess? I'd like to preserve the urls as well...
Cheers, Liam
Right - I'm using a CMS that will be publishing to two different sites (different domains too). As you can imagine. This will be a very handy tool, one login, one control panel, two very different sites...
Only we are struggling to get the domains to point to the correct sub directory of the hosting site (example1.com).
So example1.com hosts its own site and it also hosts example2.com in the sub folder example.com/2/
What I would like to do is forward, using .htaccess, the second url to the content housed at on the first url, while maintaining the URL.
For example, This URL: example1.com/2/news
would return the URL: example2.com/news
Hope that made more sense... It's giving me a headache...
You will be much happier in the long run of you put both 'sites' into subdirectories, making their set-ups essentially identical except for the subdirectory name. Otherwise, you're going to have problems sharing resources (e.g. scripts), because the relative paths from the two sites' directories will be different, even for the same shared script.
So what is the question? How to serve the file /2/news/file when the URL [example2.com...] is requested? That's a simple internal URL-to-filepath rewrite, and you should be able to suss it out with a bit of effort.
Haste makes waste... :)
Jim
I'm a typical designer really - not much of a head for domains/dns/servers etc :)
This is as far as we got:
Directing the www of example2.com to example1.com using a cname record
Then we tried using the following :
--
Header append Vary host
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/foo
RewriteRule ^.*$ http://www\.example2\.com/foo%{REQUEST_URI} [L] --
Which we hoped would rewrite the url for all pages accessed in the directory example1.com/foo by example2.com
But to no avail :(
Can anyone see an easier way to work this?
[edited by: limbo at 12:41 pm (utc) on June 22, 2009]
You will be much happier in the long run of you put both 'sites' into subdirectories, making their set-ups essentially identical except for the subdirectory name. Otherwise, you're going to have problems sharing resources (e.g. scripts), because the relative paths from the two sites' directories will be different, even for the same shared script.
No can do - CMS doesn't allow it.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/foo
RewriteRule ^.*$ http://www\.example2\.com/foo%{REQUEST_URI} [L]
Note the three important aspects of this question:
1) The rule essentially adds "/foo" into the URL-path.
2) The rule invokes a client side redirect, terminating the current HTTP transaction and telling the client that it must re-request the desired resource from a different URL. This will cause the browser to update its address bar, displaying the new URL which contains the additional /foo URL-path info.
3) Are the originally-requested and new URLs correct as stated?
Jim
We've got most of it working by mapping example2.com to example1.com and using A Records to direct the www and non www version of the domain as well - for some reason it needed both mapping and A Records. Possibly a quirk of the server configuration?
Here's what we've got.
example2 domain is showing the correct files using this:
---------------------------------------
Header append Vary host
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/b
RewriteRule ^.*$ http://www\.example2\.com/b%{REQUEST_URI} [L] we also have example1.com redirecting to www.example1.com with:
---------------------------------------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example1.com
RewriteRule (.*) http://www.example1.com/$1 [R=301,L] example2.com - points to example1.com/b/ (woot!) but it is displays: example2.com/b/ Ideally we need it to point to the right place and rewrite /b/ to /
Lastly we also want to direct example2.com to www.example2.com - I tried mimicking the second example above but it dunnae werk?
I've fiddled about for a while but cant get the right combination of rewrites. Got any ideas?