I need to make some rewrite rules, but I doesn't use Apache HTTP for years and little bit confused with rules...
Task:
1. rewrite URLs from
http://example.com/test/file.js
to http://example.com/test/1/file.js
2. if file http://example.com/test/1/file.js
is NOT found - return file http://example.com/test/1/index.html
instead;
I suppose - it must looks like this:
AllowOverride All
# if file http://example.com/test/1/file.js found - return it
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/test/1/$1 [L]
# if file http://example.com/test/1/file.js NOT found - return index.html form /1/ subdir
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/test/1/index.html [L]
Content of /test/
:
# ls -l
total 16
drwxr-xr-x 2 root root 4096 Aug 20 10:14 1
-rw-r--r-- 1 root root 6 Aug 20 08:57 index.html
-rw-r--r-- 1 root root 3 Aug 20 10:06 jj.ll
-rw-r--r-- 1 root root 64 Aug 20 08:50 test.html
And /test/1/
:
# ls -l 1
total 12
-rw-r--r-- 1 root root 15 Aug 20 11:02 file.js
-rw-r--r-- 1 root root 13 Aug 20 10:03 index.html
-rw-r--r-- 1 root root 7 Aug 20 10:14 jj.ll
But- if I try to open URL like http://example.com/test/file.js
- I'm getting file http://example.com/test/1/index.html
anyway.
Asked by setevoy
(894 rep)
Aug 20, 2015, 11:13 AM
Last activity: Jul 4, 2018, 06:49 AM
Last activity: Jul 4, 2018, 06:49 AM