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

Status
Not open for further replies.

Draft

Administrator
1st
Code:
Rewritecond %{http_host} ^phcorner.org [nc]
Rewriterule ^(.*)$ https://phcorner.org/$1 [r=301,nc]
2nd
PHP:
RewriteCond %{HTTP_HOST} !^www\.phcorner\.net$
RewriteRule (.*) https://phcorner.org/$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.org [NC]
RewriteRule ^(.*)$ https://phcorner.org/$1 [L,R=301]
 
For https:

1st
Code:
Rewritecond %{https_host} ^phcorner.org [nc]
Rewriterule ^(.*)$ https://phcorner.org/$1 [r=301,nc]
2nd
PHP:
RewriteCond %{https_HOST} !^www\.phcorner\.net$
RewriteRule (.*) https://phcorner.org/$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.org [NC]
RewriteRule ^(.*)$ https://phcorner.org/$1 [L,R=301]
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 1K
    Views
  • 1
    Participants
Last reply from:
Draft

Trending Topics

Online now

Members online
1,097
Guests online
1,375
Total visitors
2,472

Forum statistics

Threads
2,273,408
Posts
28,949,318
Members
1,235,739
Latest member
Angela012
Back
Top