Forum Moderators: phranque
I was wondering if the following problem can be solved using Mod rewrite (and/or other Apache settings).
I have a Apache 1.3.3 box with two virtual hosts defined on it.
One looks like http://example.com/ the other one http://www.example.com ... they both point out to the same php site on the same server.
Basically I want a rewrite rule to force all users that type http://example.com/foo to actually go to http://www.example.com/foo ... is it possible?
(I know that there is a php script for that, but I rather not use it).
[edited by: jdMorgan at 2:07 pm (utc) on Sep. 4, 2005]
[edit reason] Example.com [/edit]
I looked at the links you presented and I pasted the following into my .htaccess file
RewriteCond %{http_host}!^www\. [NC]
RewriteCond %{http_host} ^(.+)\.com [NC]
RewriteRule (.*) [%1.com...] [R=301,L]
RewriteCond %{http_host}!^www\. [NC]
RewriteCond %{http_host} ^(.+)\.org [NC]
RewriteRule (.*) [%1.org...] [R=301,L]
Now this does the job for all but a /forum/ directory (www.example.com/forum/ and www.example.org/forum/) which has it's own .htaccess rule (against santy and other worms and also some static url transformations).
Now basically the static url don't work anymore with http://example.com/forum/static_url/
They all get redirected to http://example.com/forum/ (which is then taken by index.php by default)
RewriteRule ^forum-([0-9]*)en.* index.php?f=$1&auto_lang=english
RewriteRule ^forum-([0-9]*).* index.php?f=$1
RewriteRule ^forums-en.html index.php?auto_lang=english
RewriteRule ^forums.* index.php
(this is a part of the rewrite rule)
Where should I place the paragraphs above in this .htacess file so that we first get the www in front, and afterwards the static_url is processed?
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.(com¦org) [NC]
RewriteRule (.*) http://www.%1.%2/$1 [R=301,L]
Jim