Forum Moderators: phranque
www.domain1.com has subfolders like so: www.domain1.com/subfolder1 etc
www.domain2.com to be diverted to www.domain1.com but I need the subfolder in this url to go to the correct subfolder like so www.domain2.com/subfolder1 to www.domain1.com/subfolder1
www.domain3.com/subfolder1 to www.domain1.com/subfolder1
The redirect has to look at the domian part, but then include the sub folder in the URL, I imagine the redirect needs to work in two parts 1- redirect the url of the domain, then to the subfolder in the redirected domain.
Can Mod rewrite do this? be grateful for the code.
Thanks in advance
This is not really any different than the various examples of non-www to www- domain canonicalization code posted here (hundreds of threads). You can try a search [google.com] to turn them up.
The redirection of the domain and folder-path can be done all at once with one HTTP redirect, but because of the way that mod_rewrite handles the HTTP_HOST variable, it does take two lines of code -- a RewriteCond and a RewriteRule.
Please review our forum charter [webmasterworld.com] for information about how to get the most out of this forum, and some links to helpful resources -- Thanks!
Jim
Been looking till my eyes seem to be falling out. I am new to rewrites and can't find an instance where I want to carry the directory paths to redirect to the destination.
What I wanted seems simple? to redirect to the subdirectory that is requested in the URL. but being new to rewrites I am afraid of screwing it up.
redirect url
www.domain1/whateversubfolder1
to
www.domain2/whateversubfolder1
all the posts I see want the reverse and to specific files and php files? in each of my subdirectories there is an index file
RewriteEngine on
#
# Internally rewrite requests for all pages in "/" to pages in /main/
#
# If not already rewritten to /main/
RewriteCond $1!^main/
# Prepend "/main" to the requested URL-path
RewriteRule (.*) /main/$1 [L]
Does /main/ mean any sub folder that is requested? there are about 40 subfolders
I can get over it by copying the destination subdirectories to the other two domains for now.. really didn't want to do that because any changes will have to be done three times, but it will buy me some time.
I found the following:
RewriteEngine on
RewriteCond %!^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
would this do the job?
does $1 mean anything after the / will be redirected?
Any help would be greatly appreciated, running out of ideas
This code will 301 redirect domain1.com/<anything-whatsoever>, domain2.com/<anything-whatsoever>, www.domain2.com/<anything-whatsoever>, domain3.com/<anything-whatsoever>, and www.domain3.com/<anything-whatsoever> to www.domain1.com/<anything-whatsoever>, carrying over the subfolders and filepaths from the original request -- Only the domain is changed:
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^domain1\.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim
Thank you so much!
I propose to drop the .ht access into each of the two domains I want redirected to the third as they are not subdomains. I therfore would interpret the code to be:
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
and for the second domain:
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^domain2\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
I have the master site as a co.uk with all the sub directories, and also have the .com and a second similar sounding domain.co.uk and didn't want to replicate the site 3 times.
I will try this on Monday and do some reading at apache.org
Thanks again
Cliff