wordpress - 这个 .htaccess RewriteRule 中的单点有什么作用?

标签 wordpress .htaccess mod-rewrite url-rewriting

使用 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)

我的问题是:
  • 我做对了第 1 到 5 行吗?
  • 第 6 行究竟做了什么?
  • 第 8 行的解释是否正确?
  • 最佳答案

    以下是答案:

    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/

    相关文章:

    .htaccess - 从裸 http 和 https 域重定向到 https ://www domain in htaccess?

    apache - htaccess - 重定向到子文件夹而不更改浏览器 URL

    css - 如何忽略使用 .htaccess 重写 css 文件

    javascript - 如何在wordpress中根据当前页面加载不同的菜单?

    apache - 删除 URL 路径开头的双斜杠

    .htaccess - Nuxt JS 服务器部署 - 如何将 URL 重定向到本地主机 :3000 using htaccess

    apache - 重定向除 ?p=* 之外的所有内容

    php - 在 wordpress 中使用 page-id 调用时不显示样式

    javascript - 我如何修改此 e.preventDefault 以在除主页之外的所有页面上工作?

    wordpress - fatal error :在1610行的C:\xampp\htdocs\wordpress\wp-includes\class-http.php中,超过30秒的最大执行时间