htaccess Elite

Hire htaccesselite professional

$25 non-refundable deposit for me to look at your request,
$175/hr if both parties agree to work request.

.htaccess tutorial


All times are UTC - 5 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Requiring the WWW
PostPosted: Sep 25th, '06, 07:45 
User avatar

Joined: Sep 24th, '06, 22:48
Posts: 240
If you would like to redirect anything from http://domain.com to http://www.domain.com (so the www is always in the URL), you can accomplish this by using the code below. This is helpful in search engine optimization and will help give your site a higher page rank.

I use the first method, but only when I can't edit the httpd.conf file directly.

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

# require non-empty HOST header
RewriteCond %{HTTP_HOST} !^$

# require case-insensitive HOST to be www.htaccesselite.com
RewriteCond %{HTTP_HOST} !^www\.htaccesselite\.com$ [NC]

# 301 redirect everything to correct www.htaccesselite.com
RewriteRule ^(.*)$ http://www.htaccesselite.com/$1 [R=301,L]

# or you can use this rewriterule
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]



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


Code:
RewriteCond %{HTTP_HOST} ^htaccesselite\.com$ [NC]
RewriteRule ^(.*) http://www.htaccesselite.com/$1 [QSA,L,R=301]



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



Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]


Last edited by produke on May 30th, '07, 02:40, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Oct 30th, '06, 14:29 

Joined: Oct 28th, '06, 01:37
Posts: 44
For sites running on a port other than 80:
Code:
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://fully.qualified.domain.name:%{SERVER_PORT}/$1 [L,R=301]




And for a site running on port 80
Code:
RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://fully.qualified.domain.name/$1 [L,R=301]


Top
 Profile  
 
 Post subject:
PostPosted: Dec 4th, '06, 07:29 
User avatar

Joined: Sep 24th, '06, 22:48
Posts: 240
And for those of you on a Windows Server using ISAPI_Rewrite, it's as simple as adding this to your .ini file...
Code:
RewriteCond Host: ^example\.com
RewriteRule (.*) http\://www\.example\.com$1 [I,RP]



Code:
#------------------------------------------
# First optional line, include only in case of errors:
RewriteEngine On
# Second optional line, include only in case of errors:
Options +FollowSymLinks
# Optional start tag, requires use of corresponding end tag as well
< IfModule mod_rewrite.c >
# ----------------- the real stuff starts here
# IF there's a host field at all, AND
RewriteCond %{HTTP_HOST} .
# IF domain does not start with www, AND
RewriteCond %{HTTP_HOST} !^www\.threadwatch
# IF subdomain is not another one of those you like
RewriteCond %{HTTP_HOST} !^sub1\.threadwatch [NC]
RewriteCond %{HTTP_HOST} !^sub2\.threadwatch [NC]
RewriteCond %{HTTP_HOST} !^sub3\.threadwatch [NC]
RewriteCond %{HTTP_HOST} !^sub4\.threadwatch [NC]
RewriteCond %{HTTP_HOST} !^sub5\.threadwatch [NC]
# THEN redirect everything to an appropriate location
RewriteRule (.*) http //www.threadwatch.org/$1 [R=301,L]
# ----------------- the real stuff ends here
# Optional end tag, only if you have used the optional start tag
< /IfModule >
#------------------------------------------


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB