Welcome to WebmasterWorld Guest from 54.226.143.14

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewrite Question.httpd.conf - no subdomains

   
6:33 pm on Jun 9, 2008 (gmt 0)

10+ Year Member



Hi, I have succesfully implemented some rewrite code in my http.conf file, for redirecting pages to the www.domain.com site instead of the non domain.com site.

I am wondering if anyone could help me with this code to add something that says: do not redirect to the www.domain.com version of the page if the domain is a subdomain ie: test.domain.com

So, I'd like to retain my redirects for
domain.com goes to www.domain.com
but no redirects if it is subdomain.domain.com

Could anyone help me with this please? Thank you!

Here is my generic code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^/(.*)$ [%{HTTP_HOST}...] [R=301,L]

10:24 pm on Jun 9, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Your code, as shown above, will not redirect requests for subdomains. The RewriteCond pattern says, "Match one or more characters starting with or containing anything but a period, followed by a period, followed by and ending with one or more characters which are anything but a period. In other words, only one period is allowed, otherwise the RewriteCond will not match and the rule will not be applied.

You might want to look around in the other config files, as it's possible that another rule is responsible for the unexpected redirection of your subdomains.

There's also one latent defect in the rule above: It could be unexpected defeated by perfectly-valid, but non-canonical requests for FQDNs or domains with appended port numbers -- or both. Ane example would be: [google.com.:80...] which is perfectly-valid, but non-canonical.

This can be handled properly by using two RewriteConds -- one being a modified version of what you already have:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+)\.?(:[0-9]+)?$ [OR]
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)(\.(:[0-9]+)?:[0-9]+)$
RewriteRule ^/(.*)$ http://www.%1/$1 [R=301,L]

Replace the broken pipe "¦" character in the second RewriteCond pattern with a solid pipe before use; Posting on this forum modifies the pipe characters.

Jim

2:12 pm on Jun 10, 2008 (gmt 0)

10+ Year Member



Hi Jim,

Thank you very much for the help on the rules!

Jessica

 

Featured Threads

Hot Threads This Week

Hot Threads This Month