Strange Apache rewritecond % {request_filename }! -S problems

Source: Internet
Author: User
Source: http://lufei-99999.blog.163.com/blog/static/748495420115845922988/

Recently, Apache is required for static website pages.
Static website functions are as follows:
When the user accesses the index.html page of the website, use the apacheappsindex.html file to check whether the file exists. If the file does not exist, switch to the index. Do path,
Index.dow.index.html is the automatically generated index.html file of the program. After the user reviews the index.html file again, the index.html file is directly added to implement the Automatic Static website function.
However, a problem occurs when you configure the Apache file and use Apache to determine whether the file exists.
Add an HTTP. conf file
Rewritecond {request_filename} ! -S
Rewriterule ^/A \. html $/B .html [L]
Access is always incorrect. When a.html is stored, both a.html and B .html files exist.
However, neither Baidu nor Google can be found.
Create a. htaccess file under the root directory
Rrwritebase/
Rewritecond {request_filename} ! -S
Rewriterule ^/A \. html $/B .html [L]
You can implement the required functions when accessing files.
I was puzzled for several days.
I suddenly want to enable the rewrite log of Apache.
Add
Rewritelog logs/Rewrite. Log
Then test the first case
The log is as follows:
127.0.0.1--[08/Jun/2011: 16: 53: 07 + 0800] [www.a.com/sid%7b0770%%rid%9e8030/initial] (2) Init rewrite engine with requested URI/a.html
127.0.0.1--[08/Jun/2011: 16: 53: 07 + 0800] [trim (3) applying pattern '^/A \. html $' to Uri '/a.html'
127.0.0.1--[08/Jun/2011: 16: 53: 07 + 0800] [www.a.com/sid%7b0770%%rid%9e8030/initial] (4) rewritecond: input = '/a.html 'pattern = '! -S' => matched
127.0.0.1--[08/Jun/2011: 16: 53: 07 + 0800] [www.a.com/sid%7b0770%%rid%9e8030/initial] (2) rewrite '/a.html'-> '/B .html'

Then test the second case.
The log is as follows:
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [www.a.com/sid%7b0688%rid%9e8030/initial] (2) Init rewrite engine with requested URI/a.html
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [www.a.com/sid%7b0688%%rid%9e8030/initial] (1) pass through/a.html
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [www.a.com/sid%7b0688%rid%9e8030/initial] (3) [perdir D: /tomcat/webapps/root/] Strip per-Dir Prefix: D:/tomcat/webapps/root/a.html-> a.html
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [Runtime (3) [perdir D:/tomcat/webapps/root/] applying pattern '. * 'to URI 'a.html'
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [Runtime (4) [perdir D:/tomcat/webapps/root/] rewritecond: input = '/a.html' pattern = '^/a.html $' => matched
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [Runtime (4) [perdir D:/tomcat/webapps/root/] rewritecond: input = 'd:/tomcat/webapps/root/a.html 'pattern = '! -S' => not-matched
127.0.0.1--[08/Jun/2011: 16: 36: 42 + 0800] [www.a.com/sid%7b0688%rid%9e8030/initial] (1) [perdir D:/tomcat/webapps/root/] Pass through D: /tomcat/webapps/root/a.html

Observe two log files
The difference is:
1: The prefix used in. htaccess is [perdir D:/tomcat/webapps/root/].
2: rewritecond: input = 'd:/tomcat/webapps/root/a.html 'pattern = '! -S' => not-matched
Input is an absolute path.
In HTTP. conf, there is a relative path.
For example, rewritecond: input = '/a.html' pattern = '! -S' => matched

Haha, it seems a little eye-catching. Is there a relative path in the HTTP. conf file, so it always matches when determining whether or not it exists.
Modify the HTTP. conf file:
   Rewritecond % {document_root} % {request_filename} ! -S
   Rewriterule ^/A \. html $/B .html [L]
And add the root directory of the document
The test is successful .!!!!
The log is as follows:
127.0.0.1--[08/Jun/2011: 16: 53: 39 + 0800] [www.a.com/sid%7b0770%%rid%9f8058/initial] (2) Init rewrite engine with requested URI/a.html
127.0.0.1--[08/Jun/2011: 16: 53: 39 + 0800] [trim (3) applying pattern '^/A \. html $ 'to url'/a.html'
127.0.0.1--[08/Jun/2011: 16: 53: 39 + 0800] [www.a.com/sid%7b0770%%rid%9f8058/initial] (4) rewritecond: input = 'd: /tomcat/webapps/root/a.html 'pattern '! -S' => not-matched
127.0.0.1--[08/Jun/2011: 16: 53: 39 + 0800] [www.a.com/sid%7b0770%%rid%9f8058/initial] (1) pass through/a.html

The input content of rewritecond is the absolute path of the file.
Haha.
I saw the usage in the HTTP. conf file and in the. htaccess file.
Rewritecond % {request_file }! -F
There is a difference.
In the. htaccess file, you do not need to add the root path of the document and % {document_root} because of the Directory level in the. htaccess file. Apache automatically adds the path
Apache in the HTTP. conf file does not automatically add the document root path.
This is my judgment based on the rewritelog file of apacher. I do not know whether the understanding is correct. If not, please leave a message for the grand knight.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.