Note that there are some explanatory texts on larger screens.

plurals
  1. PO.htaccess: Hide existing files but use them through RewriteRule
    text
    copied!<p>I have tried this several ways, read a lot of examples and questions here and still can't figure out if it can't be done at all.<br> What I want is to force access to certain files and functions using a certain URL format and deny access (fake 404) to everything else - even existing files/directories.</p> <p>This part works:</p> <pre><code>RewriteEngine On RewriteRule ^([\w]+)$ /somefolder/index.php?page=$1 [L] RewriteRule ^person/([\d]+) /somefolder/index.php?page=person&amp;id=$1 [NC,L] RewriteRule ^css/([\w]+\.css) /somefolder/css/$1 [NC,L] RewriteRule ^images/([\d]{4}-[\d]{2}-[\d]{2}/[\d]+\.(gif|jpe?g)) /somefolder/images/$1 [NC,L] </code></pre> <p>The following line, however, causes a 500 internal server error:</p> <pre><code>RewriteRule ^(.*)$ /somefolder/index.php?page=error [R=404] </code></pre> <p>I want that if /somefolder/index.php (or any other file/directory that may or may not exist) is requested by the visitor, it should return 404 and the error page. I also plan on adding this later:</p> <pre><code>ErrorDocument 404 /somefolder/index.php?page=error </code></pre> <p>The .htaccess file is in the root. Is this doable at all?</p> <p>Examples:</p> <p>(pages accessed by users and linked to by other pages)<br> <a href="http://example.com/breakfast" rel="nofollow">http://example.com/breakfast</a> -> <a href="http://example.com/somefolder/index.php?page=breakfast" rel="nofollow">http://example.com/somefolder/index.php?page=breakfast</a><br> (stylesheets used by the pages)<br> <a href="http://example.com/css/default.css" rel="nofollow">http://example.com/css/default.css</a> -> <a href="http://example.com/somefolder/css/default.css" rel="nofollow">http://example.com/somefolder/css/default.css</a><br> (images used in the documents)<br> <a href="http://example.com/images/2011-01-01/test.jpg" rel="nofollow">http://example.com/images/2011-01-01/test.jpg</a> -> <a href="http://example.com/somefolder/images/2011-01-01/test.jpg" rel="nofollow">http://example.com/somefolder/images/2011-01-01/test.jpg</a><br> (everything else)<br> <a href="http://example.com/this/may.exist" rel="nofollow">http://example.com/this/may.exist</a> -> 404 + error page</p> <p>.. which would mean that if someone attempts to get <a href="http://example.com/somefolder/css/default.css" rel="nofollow">http://example.com/somefolder/css/default.css</a> (exists), they wouldn't receive it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload