homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Rewrite - not working
Andrew Thomas

 3:16 pm on Sep 28, 2004 (gmt 0)

Im new to apache, but am trying to set setup 301 pernament redirects.

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?)




 3:36 pm on Sep 28, 2004 (gmt 0)


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]

Options +FollowSymLinks or Options +SymLinkIfOwnerMatch is required in order to use mod_rewrite. The domain names should not be end-anchored in order to prevent rule failure in case a port number is appended, e.g. "widgets.com:80/index.html".

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.


Andrew Thomas

 4:22 pm on Sep 28, 2004 (gmt 0)

thanks, that worked fine

Andrew Thomas

 8:21 am on Oct 6, 2004 (gmt 0)

I understand most of this,

RewriteCond %{HTTP_HOST} ^widgets\.com [NC,OR]

but why is the \ before the .com



 12:45 pm on Oct 6, 2004 (gmt 0)

> but why is the \ before the .com

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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved