1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 How to redirect all www to non www url?

Discussion in 'XenForo Questions and Support' started by clove28, Jul 6, 2015.

  1. clove28

    clove28 Active Member

    I'm having a problem making www url to non www url. How can I achieve this? Thanks!
     
  2. Martok

    Martok Well-Known Member

    clove28 likes this.
  3. clove28

    clove28 Active Member

  4. clove28

    clove28 Active Member

    Hi Martok,

    I've tried the first code, but it gives a wrong url for subfolders like example.com/subfolder > example.comsubfolder without the trailing /

    and the other code says too many redirect..redirect loop...
    Code:
    Header unset Pragma
    FileETag None
    Header unset ETag
    
    # 1 YEAR
    <FilesMatch "\.(ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    </FilesMatch>
    # 1 WEEK
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
    </FilesMatch>
    # 2 DAYS 172800
    <FilesMatch "\.(xml|txt|css|js)$">
    Header set Cache-Control "max-age=604800, proxy-revalidate"
    </FilesMatch>
    # 1 MIN
    <FilesMatch "\.(html|htm)$">
    Header set Cache-Control "max-age=60, private, proxy-revalidate"
    </FilesMatch>
    
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Expires "Thu, 15 Dec 2011 20:00:00 GMT"
    </FilesMatch>
    
    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)&t=([0-9]+)($|&)
    RewriteRule ^viewtopic\.php$ /index.php?threads/%3/ [R=301,L]
    
    RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)($|&)
    RewriteRule ^viewforum\.php$ /index.php?forums/%2/ [R=301,L]
    
    # Use PHP5.4 Single php.ini as default
    AddHandler application/x-httpd-php54s .php
    #
    # Uncomment the statement below if you want to make use of
    # HTTP authentication and it does not already work.
    # This could be required if you are for example using PHP via Apache CGI.
    #
    ## EXPIRES CACHING ##
    
    <IfModule mod_expires.c>
    
    # Enable expirations
    ExpiresActive On
    
    # Default directive
    ExpiresDefault "access plus 1 month"
    
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year”
    
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    
    # CSS
    ExpiresByType text/css "access 1 month”
    
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
    
    </IfModule>
    
    ## EXPIRES CACHING ##
    #<IfModule mod_rewrite.c>
    #RewriteEngine on
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
    #</IfModule>
    
    <Files "config.php">
    Order Allow,Deny
    Deny from All
    </Files>
    
    <Files "common.php">
    Order Allow,Deny
    Deny from All
    </Files>
    DirectoryIndex portal.php index.php index.html index.htm
    <IfModule mod_rewrite.c>
    
    Rewriterule ^blog/(.+)/(.+).html$        ./blog/view/blog.php?page=$1&mode=$2 [NC]
    Rewriterule ^blog/(.+).html$            ./blog/blog.php?page=$1 [NC]
    Rewriterule ^blog/(.+)/$                ./blog/view/blog.php?page=$1 [NC]
    Rewriterule ^blog/$                        ./blog/blog.php [NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    Rewriterule ^blog/(.+)/(.+)$        ./blog/view/blog.php?page=$1&mode=$2 [NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^blog/(.+)$ ./blog/blog.php?page=$1 [NC]
    </IfModule>
    
    RewriteCond %{HTTP_REFERER} !^http://pinoyexpatforum.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://pinoyexpatforum.com$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.pinoyexpatforum.com/.*$      [NC]
    RewriteCond %{HTTP_REFERER} !^http://www.pinoyexpatforum.com$      [NC]
    RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
    
    
    # Start CloudFlare:pinoyexpatforum.com rewrite. Do not Edit
    RewriteCond %{HTTP_HOST} ^pefcommunity.com
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    # End CloudFlare rewrite.
    
    
    #    Mod_security can interfere with uploading of content such as attachments. If you
    #    cannot attach files, remove the "#" from the lines below.
    #<IfModule mod_security.c>
    #    SecFilterEngine Off
    #    SecFilterScanPOST Off
    #</IfModule>
    
    ErrorDocument 401 default
    ErrorDocument 403 default
    ErrorDocument 404 default
    ErrorDocument 405 default
    ErrorDocument 406 default
    ErrorDocument 500 default
    ErrorDocument 501 default
    ErrorDocument 503 default
    
    <IfModule mod_rewrite.c>
    
        #    If you are having problems with the rewrite rules, remove the "#" from the
        #    line that begins "RewriteBase" below. You will also have to change the path
        #    of the rewrite to reflect the path to your XenForo installation.
        #RewriteBase /xenforo
    
        #    This line may be needed to enable WebDAV editing with PHP as a CGI.
        #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
        RewriteRule ^.*$ index.php [NC,L]
    </IfModule>
    
     
  5. clove28

    clove28 Active Member

    @Brogan could you help me fixing this. I'm having problem fixing this which breaks most of my urls. :(
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    I have responded to your ticket.
    All servers are different - you will just have to try different rewrite rules until you find one which works.

    Your host is probably best placed to help as they will know the server configuration and what works.
     
  7. clove28

    clove28 Active Member


    I'm in unmanaged VPS server so I'm all alone with this. What basically happening when I used this rewrite:

    RewriteCond %{HTTP_HOST} www.example.com$
    RewriteRule ^(.*)$ http://example.com$1 [R=301,L]

    was one sub-folder (I created a new folder in ".../public_html/" ) changed the url without the trailing "/". For example I have a subfolder: xenforo.com/subfolder/ which supposedly has a URL of xenforo.com/subfolder/ but the rewrite makes it xenforo.comsubfolder.

    So maybe I can change something from the rewrite to rewrite it properly? Or do I really need to contact my host for this? Thanks!
     
  8. clove28

    clove28 Active Member

    Okay I solved the problem just by putting "/" between .com and $
     

Share This Page