htaccess在localhost上的errordocument的不同路径

时间:2013-02-09 07:38:56

标签: php .htaccess errordocument

我在编辑自定义错误页面的.htaccess文件时遇到问题。

在实时服务器上,这样可以正常工作。

ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500

但是在我的localhost(WAMP)上,我的网站位于www目录下名为sms的文件夹中。所以我要将代码修改为

ErrorDocument 400 /sms/error.php?e=400
ErrorDocument 401 /sms/error.php?e=401
....and so on for all files

有没有一种简单的方法来处理这种情况,所以我不必每次都编辑这些行...谢谢..

1 个答案:

答案 0 :(得分:0)

It may be a little bit late in the day, but I had a similar problem and solved it.

It's DocumentRoot setting (in Apache configuration) that was the culprit. It has to point to the folder your site resides both on local and remote machines. Apparently in your case it was not.

You could get this kind of error if (for example) your site resided in sms directory both on local and remote machines, and in both cases the directory itself resided in default document root directory. What caused the error is that default root directory often gets overriden on server, when configuring virtual hosts.

It could look like this:

<VirtualHost *:80>
  ServerName yourdomain.com
  DocumentRoot /var/www/html/sms
</VirtualHost>

In this case default document root has been changed from default /var/www/html to /var/www/html/sms while on your local machine DocumentRoot is still set to the default value (whatever it is in WAMP).

As a solution you could create a virtual host with custom document root (that would point to the sms directory) on your local machine. It can be done by editing the httpd-vhosts.conf file (in which case you should also edit the hosts file on your machine). If you have only one site though, it would be simpler to change the default DocumentRoot setting in httpd.conf so that it points to the sms directory.