What does the single dot do in this .htaccess RewriteRule?

核能气质少年 提交于 2019-12-11 00:43:50

问题


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)?

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).

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)

My questions are:

  1. did I get lines 1 to 5 right?
  2. what exactly does line 6 do?
  3. is line 8 explanation correct?

回答1:


Here are answers:

Q1. did I get lines 1 to 5 right?

A1. yes you did

Q2. what exactly does line 6 do?

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. is line 8 explanation correct?

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.



来源:https://stackoverflow.com/questions/35303598/what-does-the-single-dot-do-in-this-htaccess-rewriterule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!