单点在此.htaccess RewriteRule中有什么作用? [英] What does the single dot do in this .htaccess RewriteRule?
问题描述
使用Wordpress作为CMS,.htaccess文件如下所示:
Using Wordpress as a CMS, the .htaccess file looks like this:
RewriteEngine On # 1. ok - enables engine
RewriteBase /blog/ # 2. ?? - sets blog directory as base for the rules
RewriteRule ^index\.php$ - [L] # 3. ?? - replaces index.php by nothing in the URL
RewriteCond %{REQUEST_FILENAME} !-f # 4. ?? - checks if request contains a file name
RewriteCond %{REQUEST_FILENAME} !-d # 5. ?? - checks if request contains a directory name
RewriteRule . /blog/index.php [L] # 6. ?? --> why this single dot (1 occurrence of a single character)?
我阅读了有关mod_rewrite的大量文档(并且仍在阅读中),我知道什么是regex以及它们如何工作,并且我的网站工作得非常好.但是我正在复制粘贴内容,不确定是否会理解.行??是我不确定的(我完全不了解第6行的功能).
I read extensive documentation (and still am reading) about mod_rewrite, I know what regex are and how they work, and I got my site working perfectly fine. Yet I'm copying-pasting and not sure to be understanding. Lines with ?? are the ones I am not sure to understand (and I don't get what line 6 does at all).
在另一个基于 https://stackoverflow.com/a/20979005 的文件中(该文件在我的网站上有效):
In another file based on https://stackoverflow.com/a/20979005 (this worked for my site):
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ # 7. ok
RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L] # 8. ?? - if it does not contain the subfolder, add it (strange as I wanted exactly to remove it from the URL but it works)
我的问题是:
- 我的第1至5行正确吗?
- 第6行到底做什么?
- 第8行的解释正确吗?
推荐答案
以下是答案:
Q1.我得到第1至5行吗?
Q1. did I get lines 1 to 5 right?
A1.是的,你做到了
A1. yes you did
Q2.第6行到底是做什么的?
Q2. what exactly does line 6 do?
A2.它说,对于任何不为空的请求(单个DOT都将匹配除着陆页以外的任何内容)转发到/blog/index.php
A2. It says for any request that is not empty (single DOT will match anything except the landing page) forward to /blog/index.php
Q3.第8行的解释正确吗?
Q3. is line 8 explanation correct?
A3.是的,这是正确的.没有什么奇怪的.您要在客户端的URL中删除/subfolder/
,但要在Web服务器收到不带subfolder/
的请求时在内部/静默地添加subfolder/
,以便您可以正确加载页面.
A3. Yes it is correct. There is nothing strange. You want to remove /subfolder/
in your URLs for your clients but want to add subfolder/
internally/silently when your web server receives a request without subfolder/
so that you can load the page correctly.
这篇关于单点在此.htaccess RewriteRule中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!