R
R
Roman2014-03-26 12:28:21
htaccess
Roman, 2014-03-26 12:28:21

How to fix incorrect redirect from www?

Hello dear experts!
The redirect to www does not work correctly on the site. For example, site.ru/razdel is redirected to http://www.site.ru, while /razdel/ gets lost somewhere.
I am far from such technical issues, so I beg you to suggest how you can make the redirect to www work fully.
.htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

RewriteCond %{HTTP_HOST} ^site.ru [NC]
RewriteRule ^(.+[^/])$ http://www.site.ru/$1/ [QSA]
redirect 301 /index.php/ http://www.site.ru

PS: The rule with index.php was set by default, for some reason cms does not work without it. Adding a slash at the end of links is necessary. redirect 301 added to remove www.site.ru/index.php/.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nowm, 2014-03-26
@Gardus

Instead of:

RewriteCond %{HTTP_HOST} ^site.ru [NC]
RewriteRule ^(.+[^/])$ http://www.site.ru/$1/ [QSA]
redirect 301 /index.php/ http://www.site.ru

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

Only it is desirable to write this not at the end of the file , but on the next line after after "RewriteBase /".
Your redirect occurs due to the fact that with the line “RewriteRule ^(.+[^/])$ www.site.ru/$1 [QSA]” you indicate that you need to show content from the page with www. At the same time, in this line we are not talking about a redirect at all, since the “QSA” flag is specified, and not “R”. And since there is no additional “L” flag in this line, the execution does not stop and the “redirect 301 /index.php/ http://www.site.ru” instruction starts working, which redirects the request to the site root.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question