Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
1.1k views
in Q2A Core by
edited by
I have a q2a website running in production, I made a backup from PHP files and MySQL and restored it on my local machine. (I use a wamp server)

Now when I type localhost in my browser the website redirects to my main domain name and opens the running q2a website.

How can I prevent redirecting from localhost to the main domain?
I changed the site_url to localhost in qa_options table and deleted .htaccess file but the same problem happened!
Q2A version: 1.5.4

2 Answers

0 votes
by
 
Best answer

Here are the exact steps I did to restore a server backup into my local (xamp) and run it properly:

1. Restore database backup into local MySQL

     These commands can be used:

  • mysql> create database dbName;
  • mysql> use dbName;
  • mysql> source c:\AddressToDumpFile\dump.sql;
2. Copy the whole backed-up files into local htdocs inside xamp installation.
3. in local qa-config.php, change the database username, password, and database name that you have restored.
4. Find table name qa_options in the local restored database and find site_url property and change it to localhost and add the restored folder name to the end. like this: http://localhost/a2qFolderName/
5. Open .htaccess file in the local and comment on all lines that have your online website's domain name.
6. Restart apache and mysql server and open url in your browser. like this: http://localhost/a2qFolderName/
Important note:
If before doing the above steps, you open the local URL in your browser for the first time, it will redirect to your online site and your browser will cache this redirection then if you do the above steps it will not work, because your browser will do the redirection and will show your online site again, to solve this after you do the above steps you should remove browser cache or use another browser and then open local URL.
I would like to thank  who helped me a lot in this process. smiley
0 votes
by
You should change the main domain in The Admin panel

General > Preferred site URL
by
I did it in the database
I changed the site_url to localhost in qa_options table, but it did not work!
by
Are you sure it has changed in the control panel of the site?
by
I changed it in my local MySQL, not the production site.
Do I need to change General > Preferred site URL in my production site? then make a backup and restore it to my local MYSQL?
Won't that break my production site if I change  "Preferred site URL" to localhost?
by
What you will do is change the link in Preferred site URL to "http://localhost"
by
Just did it on the local database but the same problem happened, unfortunately!
by
I already ran my site through Localhost and this is what I did
By the way, I have not modified anything in the database
by
But for me it did not work unfortunately!
by
So I will give you the steps I did:
1- Take a backup copy of your website files and save them on your device.
2- Take a backup copy of the database from the Cpanel, not from Phpmyadmin, where you go to Backup, choose the database and download it to your computer.
3- Put the site files in htdocs file and then log in to phpmyadmin of localhost and import the database.
4- Edit the config.php file and then open your site through the browser, it should work now without the need to fix any of the tables.
5- If the site works correctly, enter the admin control panel and modify the site link in the general, and if software errors appear, enter the plug-ins folder and delete all plugins temporarily until you are sure of the source of the error, because often the plugins do not work correctly on the local server.
Note: The link to the site is completely, for example: http://localhost/ask
by
Again it is redirecting from localhost to the production site! :(
by
You can contact me so that I can log into your device through the any desk program and try to find a solution to the problem
by
That would be great and we will share the solution here. :)
When do you have time?
I will send you a private message.
...