Forum Moderators: phranque
I have complete control of my Apache server (on Mac OS X 10.2.8).
I have a bunch of old domain names that I want to the server to convert over to a new domain name. Some of them I want to go to the root domain, some to a subdirectory. And i want this new address to show up in the users' browser's location bar. For example:
[olddomain1.com...] -> [newdomain.com...]
[olddomain1.com...] -> [newdomain.com...]
[olddomain2.com...] -> [newdomain.com...]
[olddomain2.com...] -> [newdomain.com...]
[olddomainA.com...] -> [newdomain.com...]
[olddomainA.com...] -> [newdomain.com...]
[olddomainB.com...] -> [newdomain.com...]
[newdomain.com...] -> [newdomain.com...]
I know this is probably simple, and it's fairly simpleminded to ask about this. However, I know quite abit about other Apache stuff and configujring files, and every instructional page I found about mod_rewrite is opaque to me: They either instruct in some other use for mod_rewrite that is supposedly a much more common application, or, more frustratingly, they describe what seems to be the task in extremely vague generalities which leave out important contexts and necessary specs - so either I can't figure out if it's the right application or if i can I can't figure out where to write the configuration in or what is an insert data here place holder and what is the required terms.
I NEED TO KNOW:
In what(s) file I write whatever i'm supposed to write.
Whether what I'm writing is written once for all olddomains to one new domain or is it one string of configuration data for each virtual domain, etc. etc.
On Mac OS X Apacher Server, there is a httpd.conf for most main Apache stuff, and then a httpd_macosxserver.conf which has a block of similar configurations for each virtual host.
I have access to everything on the server including every root directory for every virtual host.
Please help. Thanks!
Welcome to WebmasterWorld [webmasterworld.com]!
There are many ways to do this, but the simplest might be to point (DNS & server config) all of the domain names to one virtual server, and then straighten everything out in .htaccess in the root directory of that server. I believe that would minimize the number of repetitive rules you'd have to write. You could also do it in httpd.conf, using slightly-different mod_rewrite syntax (add a leading slash to the pattern in each RewriteRule).
Using a couple of your example groups, this should get you started:
http://olddomain2.com/ -> http://newdomain.com/
http://www.olddomain2.com/ -> http://newdomain.com/
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain2\.com
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain([A-Z])\.com
RewriteRule (.*) http://newdomain.com/section%1/$1 [R=301,L]
Ref: Introduction to mod_rewrite [webmasterworld.com]
Jim
I think that using httpd.conf would be less taxing on the server (I don't have an .htaccess file naywhere in this site).
So, can you clarify what you mean by adding a leading slash to the pattern? i.e. Where would I put this? And is that all I have to change about the examples you gave? And, while I'm at it - does it matter where in the httpd.conf file I put it?
Thanks again.
I've pasted in the code below. The "..." indicates that there is more code for the domain there, and the "****" is not in the code I saved - it's here just to indicate the new lines I put in:
...
DocumentRoot "/Users/examples/Sites"
DirectoryIndex default_example.html default.shtml default.html default.htm index.shtml index.html index.htm
AddHandler server-parsed .html .shtml .txt
...
<Directory "/Users/examples/Sites">
Options All +MultiViews +ExecCGI +Indexes
****RewriteEngine on
****RewriteCond %{HTTP_HOST} ^(www.\.)?example\.com
****RewriteRule /(.*) http://examples.org/$1 [R=301,L]
AllowOverride None
<IfModule mod_dav.c>
DAV On
</IfModule>
</Directory>
</VirtualHost>
SOME RELEVANT SITE DETAILS:
http://example.com/ is set to use as its index page default_example.html (although I also have in the settings default.html as the second choice of index file name).
The virtual server for http://example.com/ goes to the same root folder as http://examples.org/. Thus, the default_example.html page is in the same root folder as the default.html page that http://examples.org/ is set to go to.
The default_example.html page is coded to use the stylesheets /css/common.css & /css/example.css
The /default_example.html page is coded to use the stylesheets /css/common.css & /css/example.css
The /default.html page is coded to use the stylesheets /css/common.css & /css/front.css
THE RESULTS/PROBLEM:
When I rebooted the server and went to the old domain in a web browser (Apple Safari 1.2 (v125), it took longer than usual for the page to come up. When it did,
(a) http://example.com/ was still in the location bar of the browser; and
(b) it was the original default_example.html page for example.com, BUT...
(c) the page displays like it's not accessing the stylesheets: It's just using standard browser settings for fonts and link colors etc.
You can see the correct stylesheet formatting at <snip> - which goes to the same default_example.html page but for which I didn't add the new rewrite code in the virtual host settings.
Clearly, the issue here isn't whether or not my stylesheets work, but it seems like it will give someone who can figure out this problem some clues as to what exactly the problem is.
I hope someone can help! :¦
[edited by: jdMorgan at 7:42 am (utc) on Feb. 12, 2004]
[edit reason] Examplified URLs. Please see TOS. [/edit]
There's a typo/syntax error in this line:
RewriteCond %{HTTP_HOST} ^(www.\.)?example\.com RewriteCond %{HTTP_HOST} ^(www\.)?example\.com BTW, but unrelated to the problem: In this line, the "All" specifies that all options except MultiViews are enabled; Therefore, the others are redundant.
Options All +MultiViews +ExecCGI +Indexes Options All MultiViews There's something strange going on, because your rule should not be activated, and it certainly should not change your css functionality. I'm going to have to think on it for awhile. Hopefully, someone else may quickly see a problem that I'm missing here.
Jim
I've tried to follow your suggestion and now have the following:
RewriteCond %{HTTP_HOST} ^(www\.)?t2.example.com\.com
RewriteRule /(.*) http://gb7imk.example.org/$1 [R=301,L]
This works fine for [t2.example.com...] but not [t2.example.com...]
The domainname doesn't change. How would I solve this please?
[edited by: jdMorgan at 6:46 am (utc) on Feb. 13, 2004]
[edit reason] No URLs. Please see TOS. Thanks. [/edit]
OK, I saw my error and corrected that...
RewriteCond %{HTTP_HOST} ^(www\.)?t2.example\.com
RewriteRule /(.*) http://gb7imk.example.org/$1 [R=301,L]
... not that it made any difference to my problem :-(
[edited by: jdMorgan at 6:48 am (utc) on Feb. 13, 2004]
[edit reason] No URLs. Please see TOS. Thanks. [/edit]
RewriteCond %{HTTP_HOST} ^(www\.)?t2.example\.com
RewriteRule [b](.*)[/b] http://gb7imk.example.or[b]g$1[/b] [R=301,L]
Jim