evilmandarine
evilmandarine

Reputation: 4553

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

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?

Upvotes: 4

Views: 2514

Answers (1)

anubhava
anubhava

Reputation: 785561

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.

Upvotes: 3

Related Questions