UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
Our Sponsors
Sponsor Advertisements help keep UGN Security Online.



Support UGN Security by Viewing our Sponsors Products.

Want to earn prizes for clicking online advertisements? Join Rewards1.com.
Latest Postings
PC restarting or freezing for unknown reasons
by Digital Geek
03/07/10 02:42 AM
Wanted: Gas Pump
by Gizmo
02/17/10 09:39 PM
Don't vacuum your box
by Gizmo
02/17/10 09:38 PM
hidden files and microsoft websites
by Artic Warrior
02/16/10 06:54 PM
Wanted: Digital Camera
by Artic Warrior
02/16/10 06:48 PM
Naked adsl2
by Artic Warrior
02/16/10 06:46 PM
Signup Today!
Welcome to the UGN Security forums! You are currently viewing our forums as a guest which gives you limited access to most of our discussions and access to other features.

By joining our free community you will have access to post topics, communicate privately with our users (PM), respond to polls, upload content, and access many other features. Registration is fast, simple, and absolutely free; so please join our community today!

If you have any problems with the registration process or your account login, please contact us.
Topic Options
Rate This Topic
#50254 - 02/01/10 05:42 AM Forcing WWW (or Non-WWW) on URLs (via Mod Rewrite)
Gizmo Online   shocked

Community Owner
*****

Registered: 02/28/02
Posts: 7138
Loc: Portland, OR; USA
For whatever reason, you decide that you want to force one set of URLs towards your users, either ProWWW or AntiWWW. Well, with Apache there is a very simple tool to do this, it's called Mod_Rewrite and you can use a .htaccess file to do this.

There are many complicated methods to do this, over the years we've used a good set of them, that is until we found a route to just use one that's triggered for any URL (versus one for every TLD that we own).

First, your .htaccess file must tell the server that "hey, I'd like to use Mod_Rewrite" and then have a set of rules; both of these are:
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


Line 1 turns mod_rewrite on, lines 3 and 4 tell mod rewrite to look for urls missing the "www" prefix and then rewrite the URL with www attached.

Now, if you'd like to go the other route and force a non-www url on your site you can do this:
Code:
RewriteEngine on

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


This similar rule says that if the www portion of the URL is attached, to strip it away and use just the domain and the uri.

Now some users will argue that "www" is depreciated and shouldn't be used; whereas others would argue that "www" means web, and "ftp" means ftp (etc etc etc), whatever you choose (if wanting to force either) that's up to you.

From an SEO standpoint, I'd say to choose one or the other; some scripts (mainly those which use cookies) will treat both URLs as different sites, so I'd advise you go with one and stick with it.

And yes, we're in the "pro www" camp :P.
_________________________
Donate to UGN Security here.
UGN Security, Back of the Web, Elite Web Gamers & VNC Web Design Owner

Top
Our Sponsors
Sponsor Our Sponsors

Sponsor Advertisements help keep UGN Security Online.



Support UGN Security by Viewing our Sponsors Products.
Top  
#50255 - 02/01/10 05:45 AM Re: Forcing WWW (or Non-WWW) on URLs (via Mod Rewrite) [Re: Gizmo]
Gizmo Online   shocked

Community Owner
*****

Registered: 02/28/02
Posts: 7138
Loc: Portland, OR; USA
In case the above pro-www doesn't work for you, one of the others we've used is:
Code:
RewriteEngine on

rewritecond %{http_host} ^([a-zA-Z0-9]+\.net) [NC]
RewriteRule (.*) http://www.%1/$1 [R=301,L]
_________________________
Donate to UGN Security here.
UGN Security, Back of the Web, Elite Web Gamers & VNC Web Design Owner

Top



Moderator:  §intå×, Gizmo 
Featured Member
Registered: 03/14/02
Posts: 1136
Forum Stats
7031 Members
45 Forums
13863 Topics
48938 Posts

Max Online: 679 @ 09/10/09 06:08 PM
Top Posters
Gizmo 7138
UGN Security 6966
§intå× 3252
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
Sue's Husband, seif, Lestan Gregor, maryfrancisd, OrangeGrapes
7031 Registered Users
Who's Online
2 registered (Gizmo, HighLander), 387 Guests and 166 Spiders online.
Key: Admin, Global Mod, Mod
Latest News
Norton Safe Web Results
by Gizmo
03/08/10 03:17 AM
2010 Spring Clean Changelog
by Gizmo
03/01/10 12:12 PM
Recommended Reading
by Gizmo
02/27/10 01:49 PM
Cleanup
by Gizmo
02/24/10 02:15 PM


Donate
  Get Firefox!
Get FireFox!