Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.4k views
in Q2A Core by
I want to redirect all the pages to www format. For example if someone is typing domain.com then it should be directed to www.domain.com and also the inner links.

For example:

Domain.com/123/what-is-question

To

www.Domain.com/123/what-is-question

 

What code do i need to write in .htaccess file. Please provide step by step instructions as I have no knowledge of PHP or Server. I have already many questions on my website will this affect my previous links. Plz help
Q2A version: 1.5.2

1 Answer

0 votes
by

There are dozens of tutorials online, search for RewriteRule.

This should work:

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

 

by
where to put this code
by
"What code do i need to write in .htaccess file."
by
xxx.de is a porn site, r u kidding?
by
Sorry edit ;)  Not my page
by
this is what I'm using on my site:


DirectoryIndex index.php

<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrite all domains to one domain
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.gute-mathe-fragen\.de [NC]
RewriteRule (.*) http://www.gute-mathe-fragen.de/$1 [R=301,L]

# Rewrite for neat URLs
RewriteBase /
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]
</IfModule>

# and it works: try without www: http://gute-mathe-fragen.de
by
works !! THANKS
...