N
N
nalsa2015-10-25 20:49:25
htaccess
nalsa, 2015-10-25 20:49:25

How to fix .htaccess to redirect to www?

Good day to all!
I ran into such a problem - I need to organize a redirect on the site from www.example.com to example.com
I found options for how to do this, but the problem is that redirects are already configured in my htaccess. Tell me how to fix it to enable a redirect from www?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?$1 [QSA,L]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
ShamblerR, 2015-10-26
@ShamblerR

this redirect has nothing to do with the right one.
1 line includes redirects
2. if the requested filename is not equal to foul
3. redirect the entire contents of the line as a get request to the php index

# 2. Редирект без www на www
RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
   # Проверяем, не содержит ли домен www (в начале URL).
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
   # Перенаправляем URL на домен c www.

N
nalsa, 2015-10-26
@nalsa

Thanks for the answer.
But I need the redirect I provided to work too.
That is, when requesting www.example.com, redirect the entire content of the string as a get request to the PHP index, but to example.com (without www).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question