简体   繁体   中英

non-www to www redirect htaccess

I have a little problem and I don't know why is that.

I tried :

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

and

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

But no succes.

It redirect the website from : http://domain.com to http://www.domain.com but not from http://domain.com/sample-page to http://www.domain.com/sample-page

Why?!

Update : I use HHVM 3.6.6 . This can be the reason?! And place for .htaccess is in httpd-app.conf (Bitnami HHVM)

Bitnami developer here.

If you want to apply this redirection by default, you can add it in the default VirtualHost in the "installdir/apache2/conf/bitnami/bitnami.conf" file.

<VirtualHost *:80>
  ServerName app.example.com
  ServerAlias www.app.example.com
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 ...

<VirtualHost *:443>
  ServerName app.example.com
  ServerAlias www.app.example.com
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 ...

Please note that you will need to restart Apache to apply the changes.

installdir/ctlscript.sh restart

You can learn more about how to configure Apache using this link.

https://wiki.bitnami.com/Components/Apache

I hope it helps.

Jota

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM