使用 Wordpress 作为 CMS,.htaccess 文件如下所示:
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 的文档(并且仍在阅读),我知道正则表达式是什么以及它们是如何工作的,并且我的网站运行良好。然而我正在复制粘贴并且不确定是否理解。用 ??是我不确定理解的那些(我根本不明白第 6 行做了什么)。
在另一个基于 https://stackoverflow.com/a/20979005 的文件中(这适用于我的网站):
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)
我的问题是:
最佳答案
以下是答案:
Q1. did I get lines 1 to 5 right?
A1.是的,你做到了
Q2. what exactly does line 6 do?
A2。它表示对于任何非空请求(单个 DOT 将匹配除登陆页面之外的任何内容)转发到
/blog/index.php
Q3. is line 8 explanation correct?
A3.是的,它是正确的。没有什么奇怪的。您要删除
/subfolder/
在您客户的 URL 中,但想添加 subfolder/
内部/默默地当您的 Web 服务器收到没有 subfolder/
的请求时以便您可以正确加载页面。
关于wordpress - 这个 .htaccess RewriteRule 中的单点有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35303598/