Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mod_rewrite + direct www to non-www not working together

    Hello,

    I have mod_rewrite enabled on my forum. The code looks like this in .htaccess:

    Code:
    <IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} .*\.(jpeg|jpg|gif|png)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /public/404.php [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    Now, I want to redirect WWW to non-www with this code:

    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST}  ^www.myforum.eu [nocase]
    RewriteRule ^(.*)         http://myforum.eu/$1 [last,redirect=301]
    When I add the code to the end of the file, it starts to redirect www.myforum.eu/page1.html to the index.php file because of the "RewriteRule . /index.php. How could I get both www to non-www and mod_rewrite SEO friendly URL's working?

  • #2
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    To redirect www to non www it is

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •