htaccess ප්‍රශ්නයක්

adahasa

Active member
  • Apr 14, 2017
    269
    71
    28
    Colombo
    We all know how to rewrite all non www into www using following code in htaccess

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

    But how to re-write "one" / single URL with no www into www?

    I need only one URL to re-write with "WWW" without affecting all URLs.

    Eg:


    Code:
    https://example.com/sitemap.xml -----> https://www.example.com/sitemap.xml

    This cannot do using redirect, because it makes a loop.

     

    chanakadesilva

    Junior member
  • May 7, 2009
    99
    66
    18
    We all know how to rewrite all non www into www using following code in htaccess

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
    But how to re-write "one" / single URL with no www into www?

    I need only one URL to re-write with "WWW" without affecting all URLs.

    Eg:


    Code:
    https://example.com/sitemap.xml -----> https://www.example.com/sitemap.xml
    This cannot do using redirect, because it makes a loop.





    Try this :



    Redirect 302 /page1 https://www.newdomain.com/page1