Mobile app version of vmapp.org
Login or Join
Annie201

: Is a blank really a directory when dealing with mod-rewrite? I spent about 20 minutes wrapping my head around this, and finally came to a solution but did not know why it worked. The important

@Annie201

Posted in: #Apache #ModRewrite #Subdirectory #UrlRewriting

I spent about 20 minutes wrapping my head around this, and finally came to a solution but did not know why it worked. The important lines (as it relates to this question) in the apache configuration file looked like this:

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^$ /abc [L]


When I tried accessing example.com, the last rewriterule is skipped but what I do not understand is how is nothing a directory?

Based on the last three items from the way I see it, I'm checking to see if I'm requesting a file or a folder, and if not, then redirect nothing (aka the default page) to /abc.

It turns out here that RewriteCond %{REQUEST_FILENAME} !-d returns false because when I remove it and try again using the configuration shown below:

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^$ /abc [L]


the redirection then works.

Is there a reason as to why "nothing" counts as a directory?
I don't want to fall into any more illogical traps like this as I update my website.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Annie201

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

Becuase you are not checking that nothing is a directory, you are checking whether REQUEST_FILENAME is a directory (or not in this case).

Whilst the URL-path, that matches against the RewriteRule pattern, is nothing (after the directory-prefix is removed), the REQUEST_FILENAME (which contains the absolute filesystem path that the request maps to, ie. not a URL) will contain something like /home/username/public_html/ (depending on your config). This is a directory on the local filesystem, so the above RewriteCond evaluates to false.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme