| FAQ/Apache |
UserPreferences |
| cornerhost wiki | FrontPage | RecentChanges | TitleIndex | WordIndex | SiteNavigation | HelpContents | moin.sf.net |
.htaccess files are special files that allow you to customize apache on a per-directory basis. A good place to start learning about .htaccess is the official apache documentation:
You can password-protect a directory using two files called .htaccess and .htpasswd.
The .htpasswd file uses a username:cryptedpassword format, one pair per line. You can use this little program to generate the crypted parts if you want:
Save this in username:cryptedpassword format to text file as web/DOMAIN/.htpasswd (where DOMAIN is the domain you want to protect)
Then, in a plain text file called ~/web/DOMAIN/.htaccess add the following lines:
AuthType Basic AuthName "private" AuthUserFile /web/script/USER/DOMAIN/.htpasswd AuthGroupFile /dev/null <Limit GET POST PUT DELETE> require valid-user </Limit>
While the .htpasswd file can go anywhere, you should consider placing it outside the domain, for security purposes.
Example path and file permissions:
/web/script/username/.htpasswd (0754)
/web/script/username/domain/directory/ (0771)
/web/script/username/domain/directory/.httacess (0774)
Add the following line to your .htaccess file:
AddHandler server-parsed .html
You can also use SSI just by naming your file *.shtml
Your logfiles live in your ~/log directory (~/logs on mercury)... There's a subdirectory for each site. A report on the past week's traffic gets generated once a night. You can see the report by logging into the control panel.
If you don't need to have your logfiles on the server, you can just delete them.
Server Side Includes are let you include several files inside your page, so that you can reuse those files across pages. For example, if you have a menu bar on every page of your site, you can put it into one file, and then just include that file on each page. Then if the menu changes, you only have to change it in one place.
All you do is put the shared content into one file (say ~/web/shared/menu.inc or something) and then rename the pages to *.shtml and use:
<!--#include file="/web/script/USERNAME/shared/menu.inc" -->
Note: on basic account, use /web/simple instead of /web/script
If you have a script or shell account, you might also consider PHP, which can do everything SSI can and much more. The equivalent statement in PHP is:
<? include("/web/script/USERNAME/shared/menu.inc"); ?>
You can do this by creating an .htaccess file in the top level directory for your domain. Include the line:
ErrorDocument 404 /missing.html
Note: the / is important.
Yes. Put this in your .htaccess file for a directory. Change the top line to your own domain name, and this will block all access from outside your domain.
SetEnvIf Referer yoursite.com internal <Limit GET POST> order deny,allow deny from all allow from env=internal </LIMIT>
This one is for images. It shows "goway.gif" instead of the linked image.
RewriteEngine on
RewriteCond %{REQUEST_URI} !goaway.gif$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$
RewriteRule \.(gif|jpg)$ /goaway.gif [L]
Ideally, all spiders would respect robots.txt. Some don't, but you can still block them using the same approach as in the deep linking answer:
SetEnvIf User-Agent "BadSpider" badspider <Limit GET POST> order deny,allow deny from all allow from env=internal </Limit>
DirectoryIndex None
This will make requests for the directory return a "Forbidden" error message. You can also include a filename like /empty.html if you want all directories to use the same index page.
> I just created my first subdomain, and I want to make the subdomain and > a subdirectory point to the same place, namely: > > http://newstalk.eykd.net > and > http://eykd.net/newstalk/ > > will both take you to my blog, which up until now has always resided at > > http://eykd.net/newstalk/index.shtml > > I know it'd be easy to just make my > ~/web/newstalk.eykd.net > a symlink to > ~/web/eykd.net/newstalk > but I have no shell access. Any bright ideas on a painless way to do > this, or do I need to call Michal in?You can put a redirect in your .htaccess file for eykd.net to move people to the new site. That way all your traffic for the blog will wind up in the newstalk.eykd.net logfiles.
# in ~/web/eykd.net/.htaccess: Redirect /newstalk/ http://newstalk.eykd.net/
---
2005 answer: You can also do this by editing the newstalk.eykd.net site configuration in the control panel, and change the site's document root to match the subdirectory. However, with this approach, the two versions of the url would be logged separately. If you want the logs in the same place, use the Redirect rule.
A customer pointed me to this article about how having the "www" prefix on your urls might lower your google pagerank:
By default, your sites are set up to allow both versions of the domain. You can make one redirect to the other by putting something like this in your .htaccess file:
# kill the www prefix:
RewriteEngine on
RewriteCond %{HTTP_HOST} "^www"
RewriteRule ^(.*) http://example.com/$1 [R=301]
That says "if they ask for the www version, redirect to the version without the prefix..."
Make sure you change "example.com" to your actual domain!!!