Forums / All Other Contributions/Addons / .htaccess - Add "www." to URL (SSU)

.htaccess - Add "www." to URL (SSU)

Views: 5,064

Results 1 to 19 of 19
31 Jan 2010, 9:49 PM
#1
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

.htaccess - Add "www." to URL (SSU)

I'm currently using ZC 1.3.8a and SSU, but haven't found the answer to this anywhere.

I want to add "www." to all URLs if they're not specified. I've done google searches for the code but everybody has a different example. The few ones I have tried ended up preventing the page from loading.

Does anyone already have this implement that they could share?

31 Jan 2010, 11:12 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: .htaccess - Add "www." to URL (SSU)

Don't know about SSU

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]

Zen-Venom Get Bitten

1 Feb 2010, 2:31 AM
#3
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

That works for my main site, but the store is in a subfolder, and I'm still having issues.

BOF SSU

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.mysite.com$
RewriteRule ^(.*)$ http://www.mysite.com/store/$1

RewriteBase /shop/

Deny access from .htaccess

RewriteRule ^.htaccess$ - [F]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1 [E=VAR1:$1,QSA]

EOF SSU

It works for everything, except when I type in mysite.com/store (without the trailing slash)

1 Feb 2010, 3:42 AM
#4
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

I've been plugging away at this for 3 hours now, to no end. Can anyone familiar with SSU shine some light?

1 Feb 2010, 3:48 AM
#5
jamielife avatar

jamielife

Zen Follower

Join Date:
Dec 2009
Location:
Richmond, VA
Posts:
161
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

try

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

no need to add your specific domain.

1 Feb 2010, 3:56 AM
#6
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

jamielife:

try

no need to add your specific domain.
This wound up working correctly for an incorrectly-typed URL, but would re-direct a correctly typed URL back to the home page (which isn't where my store is located).

1 Feb 2010, 4:03 AM
#7
jamielife avatar

jamielife

Zen Follower

Join Date:
Dec 2009
Location:
Richmond, VA
Posts:
161
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

oh, sorry...

RewriteRule ^(.*) http://%1/store/$1 [R=301,L]

add the folder name to

1 Feb 2010, 4:09 AM
#8
jamielife avatar

jamielife

Zen Follower

Join Date:
Dec 2009
Location:
Richmond, VA
Posts:
161
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

...put it in the sub dir

1 Feb 2010, 4:28 AM
#9
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

I do have it in the sub directory, so I know that's not the issue.

The problem is I need it to add the "www.", not remove it. I tried tweaking it a little but I'm still not getting the results.

Will attack this again when I'm fresh in the morning.

5 Feb 2010, 5:46 PM
#10
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

Still no success with this...

6 Feb 2010, 2:57 AM
#11
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: .htaccess - Add "www." to URL (SSU)

bobthemolder:

Still no success with this...

Most want to remove the 3 w's but..

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

Dave
Always forward thinking... Lost my mind!

6 Feb 2010, 6:05 AM
#12
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

davewest:

Most want to remove the 3 w's but..

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


Yeah I have a few sites I'm removing the www's from but it's a preference to have them for this one.

The code almost works - but it's appending the physical file path (from the server) to the URL - possibly something to do with the rewriteBase in SSU?

edit: It's working on my test site that is located in the root folder, so it's the rewriteBase that's causing the issue...
6 Feb 2010, 6:38 AM
#13
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

This problem was partially fixed by just appending the preferred domain name to the redirect already in the SSU .htaccess portion. I figured adding code wasn't working, so what about modifying it - and it corrected 90% of the problem.

Now all the category and product pages automatically redirect, but the main page isn't.

Test site runs perfectly - again, problem with it being in a directory. It appends the physical file path from the server to the URL with the code DaveWest posted.

8 Feb 2010, 3:25 AM
#14
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

After many hours of headaches, and realizing I was just going to have more problems when I implemented SSL - I just moved my store from a subdirectory to the main directory on the website. It solved all the rewrite problems.

It was one hell of a transition but I think it will be for the better. The amazing thing is that all URLs automatically resolve to the new ones - so https://www.mysite.com/store/widget1 now automatically gets redirected to https://www.mysite.com/widget1

I don't know how or why it works, but it does. My only concern now would be making it a 301 redirect so the search engines know to modify their listings.

9 Feb 2010, 12:19 AM
#15
litepockets avatar

litepockets

Zen Follower

Join Date:
Apr 2008
Location:
Covington, Washington, United States
Posts:
206
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

how would you now make redirects for all pages/categories, etc.? I too have one of my sites like domain.com/store, and would like to remove it from the "store" directory and drop it to the root.. Not sure what will happen when I do, and then like you said comes the question of search engine indexing..

Anyone have experience with this?

11 Feb 2010, 12:16 AM
#16
bobthemolder avatar

bobthemolder

Zen Follower

Join Date:
Nov 2008
Posts:
164
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

litepockets:

how would you now make redirects for all pages/categories, etc.? I too have one of my sites like domain.com/store, and would like to remove it from the "store" directory and drop it to the root.. Not sure what will happen when I do, and then like you said comes the question of search engine indexing..

Anyone have experience with this?
With SSU - it just does it automatically. I don't know how, but it does.

I didn't figure out how to make it a 301-redirect, but over time Google will catch up. What's great is that my PR from mysite.com/store and mysite.com will eventually consolidate, into a single, higher PR :D

24 Apr 2010, 6:19 PM
#17
jdalton avatar

jdalton

New Zenner

Join Date:
Feb 2010
Posts:
24
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

hi

Found a quick way around this... rather than editing the .htaccess file under xx/store/.htaccess. Instead edit the .htaccess file under www folder. It worked for me!

24 Apr 2010, 6:35 PM
#18
g1smd avatar

g1smd

Zen Follower

Join Date:
Mar 2010
Location:
UK
Posts:
449
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

Just be sure that this doesn't result in a double redirect - a redirection chain - for non-canonical requests.

The root .htaccess is processed before any that are located in folders. Sometimes rules can clash.

Live HTTP Headers for Firefox is your friend for checking the server responses.

Online since 1995.

30 May 2011, 11:27 AM
#19
vyonte avatar

vyonte

New Zenner

Join Date:
Mar 2011
Posts:
3
Plugin Contributions:
0

Re: .htaccess - Add "www." to URL (SSU)

Hi bobthemolder,
I have the same problem with one of my shop. Did you solve this issue?