Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
1.3k views
in Q2A Core by

Hi I would like to 301 redirect all non-www URLs in my music production Q&A section.  I noticed Google are indexing the non-www version which is not right.

This is the current question2answer htaccess:

DirectoryIndex index.php
RewriteEngine On
#RewriteBase /your-sub-directory
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Any ideas how to revise the above htaccess so that it can redirect all non-www URLs to www for question2answer section only? Thanks.

 

 

 

 

3 Answers

0 votes
by

 

RewriteCond %{HTTP_HOST} ^(.*).your-domain.com [NC]
RewriteRule ^(.*)$ http://your-domain.com/$1 [L,R=301]
by
This does not work. Thanks anyway.
0 votes
by

You can redirect all of the requests for www.yourdomain.com domain to yourdomain.com by modifying your website's .htaccess file. You have to add the following lines in the beginning of the file so that the redirection is properly set up:

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

You should replace yourdomain.com with your actual domain name.

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