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

I want to redirect my q2a site from www.ask.dnoj.ir to ask.dnoj.ir.

how can i do this?

Q2A version: 1.6.1

4 Answers

+3 votes
by

 

Options +FollowSymLinks
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([^/]+) $1 [L]
RewriteCond %{HTTP_HOST} ^surak-zhauap\.kz
RewriteRule ^(.*)$ http://szh.kz/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.surak-zhauap\.kz
RewriteRule ^(.*)$ http://szh.kz/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.szh\.kz
RewriteRule ^(.*)$ http://szh.kz/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^91.201.214.204
RewriteRule ^(.*)$ http://szh.kz/$1 [R=301,L]
#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>
 
 
www.szh.kz  ->  szh.kz
www.surak-zhauap.kz  -> szh.kz
surak-zhauap.kz -> szh.kz 
 
by
where should i put these codes?
by
Place the code in your .htaccess file and save.
by
where i should replace my site URL in this code?
by
please help me
+4 votes
by
edited by

There is a .htaccess file in your q2a root,

just replace everything with this one:

For www to non-www



DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#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]


# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

</IfModule>


 

For non-www to www


DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#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]
# Redirect non-www to www:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>


 

by
It's good but its only work on the home page

see these links:

with www
------------------
http://www.ask.dnoj.ir
http://www.ask.dnoj.ir/users

------------------

with out www
-----------------
http://ask.dnoj.ir/
http://ask.dnoj.ir/users
-----------------
by
Ok, I am testing it and let you know
by
But saeed it is working for me as usual,
by
Thanks but why it's not work for all (like me)?
by
It do not work if inner pages like http://www.example.com/3/question-title
0 votes
by

Well, it can be done in a very simple way through your domain admin panel. You can refer to the post in the below link for detailed discription:

http://www.digi-mentor.com/20/how-to-redirect-my-site-to-www

Regards,

Ibrahim

www.bloggersbench.com

www.digi-mentor.com

myipinfo.bloggersbench.com

 

0 votes
by

There is well written and tested rule of all question2answer websites. You can also use in non-q2a website as well.

...