Test htaccess code offline

与世无争的帅哥 提交于 2019-12-13 04:10:25

问题


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

  1. Open the Terminal
  2. Edit the host file by typing sudo nano /private/etc/hosts
  3. Add a line containing 127.0.0.1 yourdomain.com
  4. Add a line containing 127.0.0.1 www.yourdomain.com
  5. Save the hosts file
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!