php static page htaccess how to write of htaccess?

  • 2020-05-06 12:01:03
  • OfStack

1. How do I get my local APACHE server to support htaccess

How do I get my local APACHE server to support.htaccess? Simply change apache's httpd.conf Settings to make APACHE support htaccess Open the httpd.conf file (where? APACHE directory CONF directory), open with a text editor, find
(1)
Options FollowSymLinks
AllowOverride None
Instead of
Options FollowSymLinks
AllowOverride All
(2) remove the comment
below LoadModule rewrite_module modules/mod_rewrite.so
Just
2. htaccess 3

is the directory where the #.htaccess file resides RewriteBase / # directory name
RewriteEngine on # open the engine
RewriteRule # match rule # jump path
The.htaccess file (or "distributed configuration file") in the Apache system provides a way to change the configuration for a directory by placing a file containing one or more instructions in a specific document directory to act on that directory and all its subdirectories. As a user, the commands you can use are limited. The administrator can set this by Apache's AllowOverride directive.
Directives in subdirectories override directives in more advanced directories or in the main server configuration file.
.htaccess must be uploaded in ASCII mode, preferably with permission set to 644.
Location of the error document
Common client request error return code:
401 Authorization Required
403 Forbidden
404 Not Found
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type
Common server error return code:
500 Internal Server Error
Users can use.htaccess to specify their own pre-made error warning page. In general, people can set up a special directory, such as errors, to place these pages. Then in.htaccess, add the following command:
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 / errors internalerror html
One line of instructions. The first instruction above means that for 404, when the required document is not found, the page should be shown as notfound.html in the directory /errors. It is not hard to see that the syntax is
ErrorDocument error code/directory name/file name If there is very little information you need to prompt, you don't need to make a page and use the HTML number directly in the directive, as in this example:
ErrorDocument 401 "you do not have access to this page, please give up!"
Password protected
for document access To set the user and password for a document in a directory using.htaccess, the first thing to do is to generate a text document with.htpasswd, e.g.,
zheng:y4E7Ep8e7EYV
In this case, the password is encrypted, so the user can find some tools to encrypt the password into the code supported by.htaccess. It is best not to place this document in the www directory, and it is recommended that it be placed outside the www root directory document, as this is safer.
With the authorized user documentation, you can add the following directive to.htaccess:
Es136en.htpasswd server directory
AuthGroupFile /dev/null (directory requiring authorized access)
AuthName EnterPassword
AuthType Basic (authorization type)
require user wsabstract (for users who are allowed access, require valid-user if you want all users in the table to be allowed)
Note: the parenthesis part is the comment
added by myself while learning Deny access to
from an IP If I don't want a government department to access the contents of my site, I can exclude them by adding the department's IP to.htaccess.
For example:
order allow,deny
deny from 210.10.56.32
deny from 219.5.45
allow from all
The second line rejects an IP, and the third line rejects an IP segment, i.e. 219.5.45.0~219.2.45.255
Want to say no to everyone? deny from all. Not only with IP, but also with domain names.
Protect.htaccess document
When using.htaccess to set password protection for a directory, it contains the path to the password file. For security reasons, it is necessary to protect.htaccess from others. You can do this in other ways, though, such as document permissions. However,.htaccess itself can be done by simply adding the following command:
order allow,deny
deny from all
URL steering
We may have replanned the site, migrated the documents, or changed the directory. At this point, a visit from a search engine or link from another site can go wrong. In this case, the old URL can be automatically redirected to the new address by the following command:
Redirect/old directory/old document name new document address
Or the entire directory:
Redirect old directory new directory
Change the default home page file
Generally, the default home file names are default, index, and so on. However, sometimes there is no default file in the directory, but a specific file name, such as pmwiki.php in pmwiki. In this case, it is cumbersome for the user to remember the file name to access. In.htaccess you can easily set the new default file name:
DirectoryIndex new default file name
You can also list multiple, in order to indicate the priority between them, for example,
DirectoryIndex filename.html index.cgi index.pl default.htm
Prevent hotlinking
If you don't like people linking their own pictures and documents to their web pages, you can do so with htaccess's instructions.
The instructions required are as follows:
RewriteEngine on
RewriteCond %{HTTP_REFERER}! ^ $
RewriteCond %{HTTP_REFERER}! ^ http: / / (www.)? mydomain. com /. * $[NC]
RewriteRule. (gif & line; jpg) $� F
If you don't think it looks good to have someone else's page skylit, you can use a picture instead:
RewriteEngine on
RewriteCond %{HTTP_REFERER}! ^ $
RewriteCond %{HTTP_REFERER}! ^ http: / / (www.)? mydomain. com /. * $[NC]
RewriteRule. (gif & line; jpg) $http: / / www mydomain. com/alternative image file name [R L]

Related articles: