Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_rewrite vs files vs virtual subdirectories
    text
    copied!<p>I have a site with virtual subdirectories (for languages) created by the means of mod_rewrite. They work fine. Now I need to upload some files that should be accessed via certain subdirectories only.</p> <p>Currently I can access any files via any subdirectories.</p> <pre><code>site.com/file.txt site.com/jp/file.txt site.com/es/file.txt site.com/another_file.txt site.com/jp/another_file.txt site.com/es/another_file.txt site.com/third_file.txt site.com/jp/third_file.txt site.com/es/third_file.txt </code></pre> <p>I need to access these files via the related subdirectories only, if I try to access them via unrelated directory, it should throw the 404 error.</p> <pre><code>site.com/file.txt - for english (the only language that does not have a subdirectory) site.com/jp/anoter_file.txt - for japaneese site.com/es/third_file.txt - for Spanish. </code></pre> <p>Please note that there is no pattern in file names and there are many languages. So, it is necessary to create separate rules for each file/subdirectory.</p> <p>As there are many languages and files, it could be a nightmare to write rules for each language like this:</p> <p>e.g. I want file another_file.txt to be displayed inside the jp directory only. So, I have to exclude it like this:</p> <pre><code>RewriteRule ^de/another_file.txt - [R=404] RewriteRule ^fr/another_file.txt - [R=404] RewriteRule ^es/another_file.txt - [R=404] </code></pre> <p>But I think there is a more elegant solution. As far as I understand, this could be achieved by the means of exception.</p> <p>Like this:</p> <pre><code>RewriteRule ! ^jp/another_file.txt - [R=404] - but it does not work. </code></pre> <p>Could you please assist me and let me know how to fix this expression/create a new one.?</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