I always have trouble when moving a site that I've developed in localhost into my hosting server with the .htaccess
file. Specifically with relative paths to the files. It's not hard to fix, but it's quite bothering.
For example:
Whereas ErrorDocument 404 /foo/404.php
works in the
hosting, for it to work in localhost I have to specify ErrorDocument
404 /projectroot/foo/404.php
.
When using mod_rewrite
, RewriteRule ^example/$ example.php [L,NC]
works in localhost, but for it to work in the hosting I must use
RewriteRule ^example/$ /example.php [L,NC]
(note the slash before the file name).
It could be because I'm running localhost on Windows and my hosting is on Linux, but I don't think that's the problem.
So my question is, how can I ensure the paths to the files are correct when working locally or on the remote server? What is the "working directory" for the .htaccess file?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…