redirect www to non www in subfolder

Discussion in 'Apache' started by joomir, Nov 6, 2014.

  1. #1
    I have joomla installed on root folder and another joomla installed on subfolder. I want to redirect www to non in subfolder by this code in blog htaccess:

    RewriteCond %{HTTP_HOST} ^(www\.mydomain\.com)?$
    RewriteRule ^(.*)$ http://mydomain.com/blog/$2 [R=301,L]
    Code (markup):

    it worked for root redirect but when i want browse internal page it redirect the page to home page. What is problem?
     
    joomir, Nov 6, 2014 IP
  2. postcd

    postcd Well-Known Member

    Messages:
    1,043
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #2
    postcd, Nov 25, 2014 IP
  3. joomir

    joomir Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    This code just work for root forwarding and not for internal pages
     
    joomir, Nov 26, 2014 IP
  4. abdulla al arafat

    abdulla al arafat Active Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #4
    You can have it like this:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^www\.(domain\.com)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^domain\.com$
    RewriteCond %{REQUEST_URI} !^/subfolder/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /subfolder/$1 [L]
    
    RewriteCond %{HTTP_HOST} ^domain\.com$
    RewriteRule ^(/)?$ /subfolder/index.php [L]
    Code (markup):
     
    abdulla al arafat, Dec 13, 2014 IP