Forum Moderators: phranque
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} example\.com
RewriteRule (.*) http://example.com/video.htm$1 [L]
I am trying to redirect the domain 'example.com' to a page video.htm. The video.htm is a file located in the same directory where the domain points. Can you please explin what I am doing wrong?
[edited by: jdMorgan at 5:12 pm (utc) on July 12, 2006]
[edit reason]
[1][edit reason] No specific URLs, please. See TOS. [/edit] [/edit][/1]
This does not sound right, so I suggest you carefully think about exactly which requests you do and do not wish to redirect to this video.htm file. Until the problem is well-defined, it can be dangerous to write and test code...
Also, do you want 'video.htm' to be listed as your site's home page in search results?
Is this code intended for use in .htaccess or in httpd.conf or conf.d?
Jim
I have 4 doamins and 4 files in the account root. When I access any domain it will show up a default index.html file. I want domains to show differnt files:
domain1.com should show video1.html
domain2.com should show video2.html
domain3.com should show video3.html
domain4.com should show video4.html
All the files are located in the same webdirectory root.
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
RewriteRule ^$ /video-one.htm [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com
RewriteRule ^$ /video-two.htm [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com
RewriteRule ^$ /video-three.htm [L]
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain4\.com
RewriteRule ^$ /video-four.htm [L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain([1-4])\.com
RewriteRule ^$ /video%2.htm [L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain(oneŠtwoŠthreeŠfour)\.com
RewriteRule ^$ /video%2.htm [L]
An alternative to the multiple-rule approach is to use an association trick. This would be most useful if you had many domains and many video pages which had no direct name relationships with each other.
RewriteCond %{HTTP_HOST}<>video-uno.php ^(www\.)?domain-apple\.com[^<]*<>(.+)$ [OR]
RewriteCond %{HTTP_HOST}<>movie-two.htm ^(www\.)?domain-pears\.com[^<]*<>(.+)$ [OR]
RewriteCond %{HTTP_HOST}<>cine--tres.pl ^(www\.)?domain-peach\.com[^<]*<>(.+)$ [OR]
RewriteCond %{HTTP_HOST}<>flick-su.html ^(www\.)?domain-mango\.com[^<]*<>(.+)$ [OR]
RewriteCond %{HTTP_HOST}<>films-chi.htm ^(www\.)?domain-plums\.com[^<]*<>(.+)$
RewriteRule ^$ /%2 [L]
The "^$" pattern in all of the above rules is intended to match only requests for the domain root, such as "example.com/". This avoids the problems you'll have if you use a pattern that will match (and therefore rewrite or redirect) *any* file. For example, you *do not* want to rewrite or redirect requests for robots.txt, favicon.ico, labels.rdf, labels.xml, or w3c/p3p.xml or any custom error document files -- doing so will cause you very serious problems.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim