D
D
DenimTornado2014-08-10 19:26:22
htaccess
DenimTornado, 2014-08-10 19:26:22

How to fix .htaccess for redirect without www?

Hello!
There is a site with .htaccess:

ErrorDocument 403 /access/forbidden
ErrorDocument 404 /page/not/found
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options -Indexes
    RewriteEngine	on 
    RewriteCond     %{SCRIPT_FILENAME}  !-f
    RewriteCond $1 !^(index\.php|robots\.txt|images|style|scripts)
    RewriteRule		^(.+) index.php [L]

    #RewriteCond %{HTTP_HOST} !^mysite\.ru$ [NC]
    #RewriteRule ^(.*)$ http://mysite.ru/$1 [R=301,L]
</IfModule>

I added the commented out lines by googling. The goal is that all links from www should be redirected to similar ones without www. Without a code, it opens both with www and without www. Everything is fine with my main lines, the rest are transferred to /index.php
How to fix it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DenimTornado, 2014-08-10
@DenimTornado

Everything just turned out, the order of the rules failed.
Here is the correct option:

ErrorDocument 403 /access/forbidden
ErrorDocument 404 /page/not/found
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    Options -Indexes
    RewriteEngine	on 
    RewriteCond     %{SCRIPT_FILENAME}  !-f
    RewriteCond %{HTTP_HOST} !^mysite\.ru$ [NC]
    RewriteRule ^(.*)$ http://mysite.ru/$1 [R=301,L]
    RewriteCond $1 !^(index\.php|robots\.txt|images|style|scripts)
    RewriteRule		^(.+) index.php [L]
</IfModule>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question