I need to create a following rule to place in my .htaccess
- For each request i'd like to execute file/path in subfolder subdir.
- If the file doesn't exist there then i'd like to forward this request to index.php
Let say that .htaccess iw placed at http://domain/folder
When the user opens url http://domain/folder/Subfolder/xxx.html he should recieve file from http://domain/folder/subdir/Subfolder/xxx.html
So these rules have to consider the fact that there are subfolders inside subdir. (Different structures of subfolders :-) And only if the path under subdir doesn't exist the request should be forwarded to index.php
Plase help :)
ps This is a followup question to my previous one. It is quite different and includes the fact that there are subfolders inside subdir. -> mod_rewrite: How to search in local folder, subfolder and then redirect to index.php
Try adding the following to the
.htaccess
file in theroot/folder
directory of your site.I am assuming you want to send the request to the index.php in the root dir. If it is in the folder directory instead, change the last rule to
Why not simply use an Alias:
And redirect to index.php in your 404 page? It has the advantage, 404 is still caught into the weblog.
This should do it:
An update with a slight optimization.
Change log:
RewriteBase commented for use of relative path.
Checking for /file.ext (or whether in current directory). the below will check whether file is present in current directory.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^[^/]+\.[^/]+$ - [NC,L]
captures current directory in %1 and the file.ext in %2