Forum Moderators: phranque
eg www.widgets.com
and www.red-widgets.com
both redirect to www.widgets.co.uk
I used the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^widgets.com$ [NC]
RewriteCond %{HTTP_HOST} ^red-widgets.com$ [NC]
RewriteRule ^(.*)$ [widgets.co.uk...] [R,L]
when run, the site just says "forbidden"
Is the above code correct?
Without asking my hosts, is there a way to see which modules/directives are running on the server? (code to detect them?)
thanks
I'm assuming you've placed the code in .htaccess in your Web root directory. If so, try the following:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^widgets\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?red-widgets\.com [NC]
RewriteRule ^(.*)$ http://www.widgets.co.uk/$1 [R=301,L]
This is a relatively simple rewrite, so if it does not work, then it's likely that mod_rewrite is not enabled on your server -- Check your server error log to see what it says.
Jim
Because the period has special meaning to the regular-expressions pattern-matching language used in mod_rewrite. Without a preceding the slash, a period in a pattern means "match any character." Any character that has special meaning in regular expressions must be escaped if used inside a pattern.
In this case, it is used to specify that you want a literal period to match, and not just any character.
More info is available in the regular-expressions tutorial cited in our charter.
Jim