Forum Moderators: phranque

Message Too Old, No Replies

htaccess - non www redirection

         

maxbear

7:51 am on Jul 29, 2007 (gmt 0)

10+ Year Member



Hello,

I found a code which redirect non www.
<snip>

Options +Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

There is a problem. As you see in the code, it specify on example.com only. But I use 1 wordpress to manage a lot of sites. So it's impossible for me to state 1 domain or all domains.

Is it possible not to specify on any domain and domain extensions (i might use .com .net or .org)?

Thanks.

[edited by: jdMorgan at 2:16 pm (utc) on July 29, 2007]
[edit reason] No URLs, please. See TOS. [/edit]

g1smd

5:24 pm on Jul 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you want to redirect .org to .org and .net to .net or do you want to redirect all of them to .com?

If you want the first option, then just add another two-line rule to the configuration for each domain to be redirected.

If you want to redirect all of them to .com then the fist line should be:
RewriteCond %{HTTP_HOST} !^www\.example\.com

OR, more long-winded, a rule for:
RewriteCond %{HTTP_HOST} ^example\.(com她rg好et在iz)
and another for:
RewriteCond %{HTTP_HOST} ^www\.example\.(org好et在iz)

maxbear

8:51 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



Thanks a lot.

I want com -> com, net -> net and org -> org.

Is it possible not to list example.com in the htaccess and I can still redirect all domains? Something like:

RewriteCond %{HTTP_HOST} ^*.\.com

I don't know whether it works or not.

g1smd

9:04 pm on Jul 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do all these domains serve the same content?

maxbear

10:23 pm on Jul 29, 2007 (gmt 0)

10+ Year Member



No they don't.

I use 1 wordpress to manage them all. Wordpress knows which site to show what contents.

jdMorgan

3:42 am on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adjust the RewriteCond patterns so that any of your valid %{HTTP_HOST}s without "www" are recognized and redirected to [%{HTTP_HOST}...]

That's about all it takes -- You can use the server variables in the substitution URL.

Jim