Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-10-19 09:17:04

element
Member
Registered: 2009-11-18
Posts: 99

Redirect www to no www

Trying to do a 301 redirect from www to no www but every time index.php get added to the url. I tried according to http://no-www.org/ and

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]

and

RewriteEngine On
RewriteCond %{HTTP_HOST} !^your-site.com$ [NC]
RewriteRule ^(.*)$ http://your-site.com/$1 [L,R=301]

This is especially annoying because it messes with mlp.

Last edited by element (2010-10-19 09:19:06)

Offline

#2 2010-10-19 13:47:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

Re: Redirect www to no www

which and where is your site?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2010-10-19 16:33:39

element
Member
Registered: 2009-11-18
Posts: 99

Re: Redirect www to no www

I haven’t implemented it yet …

The reason why I want no www is because www and no www are duplicate content now.

Last edited by element (2010-10-20 08:10:01)

Offline

#4 2010-10-19 16:37:53

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Redirect www to no www

Offline

#5 2010-10-19 16:41:02

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Redirect www to no www

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	# 301 redirect to domain without 'www.'
	RewriteCond %{HTTP_HOST} ^www.my-domain.com$ [NC]
	RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]
</IfModule>

Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#6 2010-10-19 16:48:05

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: Redirect www to no www

If you want http://www.anydomainname.com to forward to http://anydomainname.com (i.e. not specifically naming the domain) try this:

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

Offline

#7 2010-10-19 17:49:19

element
Member
Registered: 2009-11-18
Posts: 99

Re: Redirect www to no www

Pat64, thanks for a solution but it doesn’t solve anything.
The main problem is when I type www.domain.com it get redirect to domain.com/index.php instead of domain.com/nl/
I also tried it on a site that doesn’t have mlp and same problem, don’t want no index.php added.

Last edited by element (2010-10-22 09:20:43)

Offline

#8 2010-10-19 18:30:50

element
Member
Registered: 2009-11-18
Posts: 99

Re: Redirect www to no www

I have it working with

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

Notice the / before (.*), no idea what it does.
But only when I type www.domain.com, when I type www.domain.com/section, doesn’t get redirected to domain.com/section. Is this normal behaviour?

Last edited by element (2010-10-19 18:32:19)

Offline

#9 2010-10-19 20:31:18

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Redirect www to no www

Can you post the full .htaccess? Maybe it’s something else in there. I have it (without that forward slash) working on an MLP site.

Offline

#10 2010-10-19 22:26:21

element
Member
Registered: 2009-11-18
Posts: 99

Re: Redirect www to no www

Full .htaccess

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]
	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php
	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
	# 301 redirect to domain without 'www.'
	RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
	RewriteRule ^/(.*)$ http://domain.com/$1 [R=301,L]
</IfModule>
#php_value register_globals 0

Last edited by element (2010-10-20 08:10:45)

Offline

#11 2010-10-19 22:44:48

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Redirect www to no www

Mine (working) looks like this, as you can see it’s almost exactly the same, except for the order (and the slash). Not that I’d expect the order would make a difference, but you could give it a try.

#DirectoryIndex index.php index.html
#Options +FollowSymLinks
#Options -Indexes
<IfModule mod_rewrite.c>
	RewriteEngine On
	#RewriteBase /
	RewriteCond %{REQUEST_FILENAME} -f [OR]
	RewriteCond %{REQUEST_FILENAME} -d
	RewriteRule ^(.+) - [PT,L]
        # 301 redirect to domain without 'www.'
        RewriteCond %{HTTP_HOST} ^www\.spazio-at-home\.be$ [NC]
        RewriteRule ^(.*)$ http://spazio-at-home.be/$1 [R=301,L]
	RewriteCond %{REQUEST_URI} !=/favicon.ico
	RewriteRule ^(.*) index.php
	RewriteCond %{HTTP:Authorization}  !^$
	RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
#php_value register_globals 0

Offline

#12 2010-10-19 23:00:16

element
Member
Registered: 2009-11-18
Posts: 99

Re: Redirect www to no www

Weird, apparently the order does matter. It seems to be working now.

Offline

Board footer

Powered by FluxBB