What's new

Tutorial Redirect non www url's to www / vice versa in 4 different ways

Status
Not open for further replies.

Draft

Administrator
Administrator
Joined
Jan 23, 2011
Posts
16,380
Solutions
106
Reaction
65,053
Points
10,470
1st
Code:
Rewritecond %{http_host} ^phcorner.net [nc]
Rewriterule ^(.*)$ https://phcorner.net/$1 [r=301,nc]
2nd
PHP:
RewriteCond %{HTTP_HOST} !^www\.phcorner\.net$
RewriteRule (.*) https://phcorner.net/$1 [R=301,L]
3rd
Code:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
4th
PHP:
RewriteCond %{HTTP_HOST} ^phcorner.net [NC]
RewriteRule ^(.*)$ https://phcorner.net/$1 [L,R=301]
 
For https:

1st
Code:
Rewritecond %{https_host} ^phcorner.net [nc]
Rewriterule ^(.*)$ https://phcorner.net/$1 [r=301,nc]
2nd
PHP:
RewriteCond %{https_HOST} !^www\.phcorner\.net$
RewriteRule (.*) https://phcorner.net/$1 [R=301,L]
3rd
Code:
RewriteCond %{https_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{https_HOST}/$1 [R=301,L]
4th
PHP:
RewriteCond %{https_HOST} ^phcorner.net [NC]
RewriteRule ^(.*)$ https://phcorner.net/$1 [L,R=301]
 
Status
Not open for further replies.

Similar threads

Back
Top