Quick .htaccess edit

Discussion in 'Site & Server Administration' started by degreubiwa, Jul 15, 2017.

  1. #1
    I want to redirect all inner url to non-www in following .htaccess

    How to do it ?

    RewriteEngine On
    RewriteRule ^([^/]*)/([^/]*)\/$ /game.php?id=$1&title=$2 [L]
    RewriteRule ^([^/]*)\/$ /index.php?page=$1 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)\/$ /category.php?cid=$1&page=$2&title=$3 [L]
    RewriteRule ^sitemap.xml$ sitemap.php [L]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
    Code (markup):

     
    degreubiwa, Jul 15, 2017 IP
  2. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #2
    You want to direct all URLs with www to non-www? I see no https, so maybe something like this will work:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.yoursite\.tld [NC]
    RewriteRule ^(.*)$ http://yoursite.tld/$1 [L,R=301]
    Code (markup):
    Replacing "yoursite" and "tld" with the domain and .com or whatever you are using.
     
    billzo, Jul 16, 2017 IP
  3. RoseHosting

    RoseHosting Well-Known Member

    Messages:
    230
    Likes Received:
    11
    Best Answers:
    11
    Trophy Points:
    138
    #3
    Generic rule:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
    Code (ApacheConf):
     
    RoseHosting, Jul 23, 2017 IP