/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Not really PHP, but sort of

This is from no-www.org:

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

How can it be made to require the www, instead of stripping it out, without hard-coding the domain name every time like I’ve been doing with this:

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

TIA

ayvegh

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@ayveghauthorNov 25.2008 — Bump?

This should be relatively simple, just not for me ?
Copy linkTweet thisAlerts:
@chrisranjanaNov 25.2008 — How about

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]

RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Copy linkTweet thisAlerts:
@ayveghauthorNov 25.2008 — How about

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]

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

Thanks for trying, but that would just result in a loop.

Do you know how rewrites work?
Copy linkTweet thisAlerts:
@chrisranjanaNov 25.2008 — A valid point..

How about you make the ^www match optional ?
Copy linkTweet thisAlerts:
@ayveghauthorNov 26.2008 — ? Not sure how I would do that, but I don't think I want to make it optional.

I'm basically trying to figure out a "domain-insensitive" force-www redirect.
Copy linkTweet thisAlerts:
@ayveghauthorJan 07.2009 — Solved with this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Figured it out myself. ?

ayvegh
×

Success!

Help @ayvegh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...