问题
I wanted to test my website offline, but this is my problem:
How can I test
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
offline?
回答1:
If I understood correctly the question, all you have to do is make sure that the name of your website points to your local PC/Server. Here's how to do it in OSX, with the following assumptions:
- You will be pointing to your local machine, with address 127.0.0.1
- Your domain name is yourdomain.com.
Replace the above with appropriate values.
How to edit the host file in OSX
- Open the Terminal
- Edit the host file by typing
sudo nano /private/etc/hosts
- Add a line containing
127.0.0.1 yourdomain.com
- Add a line containing
127.0.0.1 www.yourdomain.com
- Save the hosts file
- Empty the DNS cache by running the command
dscacheutil -flushcache
Now, every time you try to open yourdomain.com, it will try to connect to your local machine. To undo the above, simply open the file again and comment out (or delete) the lines you added, then flush the DNS cache.
来源:https://stackoverflow.com/questions/12014755/test-htaccess-code-offline