apache turns on pseudo static method sharing
- 2020-05-09 19:44:02
- OfStack
Environment:
System Windows
Apache 2.2
Load Rewrite module:
Find it in the conf directory, httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so
For this sentence, remove the "#" from the preceding comment, or add this sentence.
Allow ".htaccess "files in any directory, change" AllowOverride "to" All "(default is" None ") :
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be " All " , " None " , or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
You cannot directly create ".htaccess "on the Windows system. You can use" echo a "from the command line > .htaccess "is created and then edited using notepad.
Simple application of Apache Rewrite module:
All of Rewrite's rules are based on Perl style regular expressions, and you can write code that meets your jump requirements with the following basic example.
1. Request a jump
The purpose is to jump to another domain if the request is for a.jsp file.
. For example: access www ofstack com/a php jump to b. ofstack. com/b php page, visit www. ofstack. com/news/index php jump to b. ofstack. com/news/index php web pages
Note: not use HTML meta in technology or javascript way, because www. ofstack. com/a php this file does not exist, using Apache2. 2 Rewrite module in server.
Modify the configuration file httpd.conf for.htaccess or apche and add the following
RewriteEngine on
# open Rewrite The module
RewriteRule (.*)\.php$ http://b.ofstack.com/$1\.jsp [R=301,L,NC]
# Intercept all .jsp Request, jump to http://b.ofstack.com/ Plus the original request plus .php . R=301 for 301 Jump, L for rewrite The rule ends here, NC Is case insensitive
2, domain name jump
If the request is for all URL under old.ofstack.com, jump to b.ofstack.com
RewriteEngine on
# open Rewrite The module
RewriteCond %{REMOTE_HOST} ^old.studenthome.cn$ [NC]
# for host for old.ofstack.com The host does the processing, ^ Is the start character, $ Is the ending character
RewriteRule (.*) http://b.ofstack.com/$1 [R=301,L,NC]
3. Prevent hotlinking
If you don't want the images on this site to be called by other sites, you can add the following content in the configuration file httpd.conf of.htaccess or apche
RewriteEngine on
# open Rewrite The module
RewriteCond %{HTTP_REFERER} !^$
# If you do not enter the image address directly
RewriteCond %{HTTP_REFERER} !img.ofstack.com$ [NC]
# And if not img.ofstack.com All subdomains are called
RewriteCond %{HTTP_REFERER} !img.ofstack.com/(.*)$ [NC]
RewriteCond %{HTTP_REFERER} !zhuaxia.com [NC]
RewriteCond %{HTTP_REFERER} !google.com [NC]
RewriteCond %{HTTP_REFERER} !google.cn [NC]
RewriteCond %{HTTP_REFERER} !baidu.com [NC]
RewriteCond %{HTTP_REFERER} !feedsky.com [NC]
RewriteRule (.*)\.(jpg|jpeg|jpe|gif|bmp|png|wma|mp3|wav|avi|mp4|flv|swf)$ http://clin003.com/err.jpg [R=301,L,NC]
# Intercept all .jpg or .jpeg ... Request, jump to http://clin003.com/err.jpg Error image, note: this image cannot be under the original domain name, also cannot be in this .htaccess Files are effectively controlled in folders
4. No need to define.htaccess file
Add at the last line of Apache2\conf\ httpd.conf
RewriteEngine On
RewriteRule ^(.*)-htm-(.*)$ $1.php?$2
Restart Apache
Log in the background to open all false