homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Apache httpd.conf verify subdomain www is www utilizing apache
verify www using apache

 10:13 am on Oct 20, 2009 (gmt 0)

Hi everyone. LOVE THE FORUM! can't believe how much it has helped me. I'm trying to configure my apache's configuration file to verify that the subdomain is on the server.

The problem that I've run into is cookies are enabled for www.domain.com I currently use this snippet (think I even found it on here) to redirect [domain.com...] requests to [domain.com...]

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ [domain.com...] [L,R=301]

What I've been losing hair folicles over is, some users find it fun (or something) to go to:
which then removes settings that are set by cookies.

Is there a way to only allow www.domain.com (or a subdomain...will post about that too in a different topic).




 3:49 pm on Oct 20, 2009 (gmt 0)

You should have also found this snippet, which uses a negative match to ensure that only "www" is accessible:

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

The allowance for a blank HTTP_HOST prevents an infinite loop if the request is from a true HTTP/1.0 client (they don't send the Host header, leaving that variable blank, which would cause a loop if not handled).



 7:05 pm on Oct 20, 2009 (gmt 0)

Thank you jdMorgan....Your really awesome, your postings have helped me out so much!


 11:13 pm on Oct 20, 2009 (gmt 0)

An extra slash gets added to the end of my url when I go to...
the result is then converted, because of the settings below in my apache config
This doesn't affect my server from serving pages properly, just trying to understand why it does this. With it doing this of course it also turns all links to

any suggestions. Thank you much.....

Below is the code snippet:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^(iqc)(.*) http://www.example.com/imagehosting.php?$2 [NC]

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

BY THE WAY JDMORGAN....your code worked flawlessly. Thank you again.


 12:31 am on Oct 21, 2009 (gmt 0)

Nevermind...I solved it.

In case others need a solution, I changed the slash at the end in lines 3 and 7:
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RewriteRule ^(.*)$ http://www.example.com$1 [R=301,L]

So far this works fine so don't know if it will cause any errors later.


 12:34 am on Oct 21, 2009 (gmt 0)

For use in httpd.conf, but *outside* of any <Directory> container, your RewriteRule patterns should start with a slash, as in ^/(.*)$ and ^/(iqc)(.*)$

Note that in that second case, the first set of parentheses isn't needed, since you are discarding "iqc". So you can remove those parentheses, and back-reference $1 instead of $2.


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