R
R
ryzhak2014-12-16 00:02:09
Yii
ryzhak, 2014-12-16 00:02:09

How to set up redirect from non-www to www in yii2?

Hello
I'm not very friendly with Apache configs.
In general, a site will be deployed on yii2 with a basic application template. I just can’t make the redirect from bookiebeater.net to www.bookiebeater.net
work. Here is the config itself from sites-enabled:

<VirtualHost *:80>
  ServerAdmin [email protected]
        ServerName www.bookiebeater.net
        ServerAlias bookiebeater.net

  DocumentRoot /var/www/web
  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>
  <Directory /var/www>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I understand correctly that for a redirect you need to throw .htaccess into /var/www, and not into /var/www/web ?
Here is the .htaccess in /var/www:
RewriteEngine On

RewriteCond %{HTTP_HOST}  ^bookiebeater.net [nocase]
RewriteRule ^(.*)         http://www.bookiebeater.net/$1 [last,redirect=301]

And here is the htaccess in /var/www/web:
RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

mod_rewrite, mode_alias enabled
Please tell me where to dig
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2014-12-16
@Nc_Soft

You need to throw .htaccess in the DOCUMENT_ROOT of the domain, i.e. in /var/www/web

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question