Mobile app version of vmapp.org
Login or Join
Fox8124981

: Is there a "current directory" variable in .htaccess RewriteRule? In a .htaccess file in the subfolder "/preview" (not in document root), I have this rule: RewriteRule !^public/ /preview/forbidden.php

@Fox8124981

Posted in: #Htaccess

In a .htaccess file in the subfolder "/preview" (not in document root), I have this rule:

RewriteRule !^public/ /preview/forbidden.php [L,R]


It redirects all /preview/"something" requests that are not in /preview/public/ to the fobidden message.

However, I don't like the fact that the directory name "preview" is in the .htaccess file. I would like to copy the entire website to another folder or server simply by copying the file without having to change the .htaccess file.

So, is it possible to achieve the effect of that rule in some other way?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Fox8124981

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

Your regular expression (regex) says something like this:

If path is NOT /public then goto /preview/forbidden.php

...so that if placed in the /preview directory, anyone who goes to the /preview directory is redirected to the forbidden.php page.

Try these options:

RewriteRule !^index.php$ forbidden.php

RewriteRule !^index.php$ /forbidden/index.php


The first one assumes a forbidden.php in each directory while the second utilizes one forbidden.php for any directory you place the .htaccess into. I assumed that there is a valid page for each directory. If not then try this:

RewriteRule !^forbidden.php$ forbidden.php

RewriteRule !^forbidden.php$ /forbidden/index.php


I try and keep just one .htaccess in the root directory if possible. There are times where I do create a specific .htaccess file for a particular directory. I do this for simplicity.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme