我绝对是新的mod重写的东西。
注意: – 这里的URL很常见,并且在同一主机上的所有文件夹和子文件夹。
用户用来访问其网页的http://myurl.com/1234/filename.jpg是http://myurl.com/1234/filename.jpg
这里子文件夹的名称是一个整数是唯一的,并由另一个应用程序dynamic生成。
子文件夹存储特定于个人用户的图像。
所以文件夹结构如下
main1 = document root main2 is another folder within main1 or document root. /main1/1234/filename.jpg /main1/5678/filename.jpg /main1/2345/filename.jpg /main1/1212/filename.jpg /main1/main2/2367/filename.jpg /main1/main2/8790/filename.jpg /main1/main2/9966/filename.jpg
所以,我想写一个重写规则,以便如果用户试图input
http://myurl.com/1234/filename.jpg,
重写规则将需要查看文件的位置并为请求提供服务; 所以请求http:/myurl.com/1234/filename.jpg实际页面位于/main1/1234/filename.jpg,然后需要从该文件夹提供该页面。
因此,如果其他用户以http://myurl.com/9966/filename.jpg的forms提出请求,它应该提供以下目的地的页面/main1/main2/9966/filename.jpg
如果问题还不清楚,请告诉我。
这是我迄今为止所做的,根本不起作用。
RewriteCond {DOCUMENT_ROOT}/%{REQUEST_FILENAME} -f RewriteRule ^(.*)$ {DOCUMENT_ROOT}/$1 [L] RewriteCond {DOCUMENT_ROOT}/main2/%{REQUEST_FILENAME} -f RewriteRule ^(.*)$ {DOCUMENT_ROOT}/main2/$1 [L]
任何帮助真的很感激
编辑@ShaneMadden请find详细信息该configuration位于.htaccess文件; 请find.htaccess的详细信息
RewriteEngine on RewriteCond %{REQUEST_URI} ^/main1/\/. RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(main1)(/\/.+)$ $1/main2/\$2
编辑:
奥利维尔,谢谢你的帮助。 请看下面的细节。
httpd.conf文件
DocumentRoot "/WebServer/Documents"
目录列表
ls -lRt /WebServer/Documents/ -rw-r--r-- index.html -rw-r--r-- .htaccess drwxrwxrwx main1 drwxrwxrwx 456231 (Is a folder) ./WebServer/Documents/main1/: drwxrwxrwx 566432 ./WebServer/Documents/456231/: -rwxrwxrwx one.jpg ./WebServer/Documents/main1/566432: -rwxrwxrwx one.jpg
.htaccess文件
RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -f RewriteRule (.*) %{DOCUMENT_ROOT}/$1 [L] RewriteCond %{DOCUMENT_ROOT}/main1/%{REQUEST_FILENAME} -f RewriteRule (.*) %{DOCUMENT_ROOT}/main1/$1 [L]
访问URL的 – > http:// localhost:80 /
::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/ -> ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '' ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/ -> ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '' ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/ ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/index.html -> index.html ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri 'index.html' ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/index.html' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/index.html -> index.html ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri 'index.html' ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/index.html' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:52:54 +0000] [localhost/sid#10090f128][rid#10099c8a8/subreq] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/index.html
2.) http:// localhost:80/566432 / one.jpg
::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] add path info postfix: /WebServer/Documents/566432 -> /WebServer/Documents/566432/one.jpg ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/566432/one.jpg -> 566432/one.jpg ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '566432/one.jpg' ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents//WebServer/Documents/566432' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] add path info postfix: /WebServer/Documents/566432 -> /WebServer/Documents/566432/one.jpg ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] strip per-dir prefix: /WebServer/Documents/566432/one.jpg -> 566432/one.jpg ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (3) [perdir /WebServer/Documents/] applying pattern '(.*)' to uri '566432/one.jpg' ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (4) [perdir /WebServer/Documents/] RewriteCond: input='/WebServer/Documents/main1//WebServer/Documents/566432' pattern='-f' => not-matched ::1 - - [26/Nov/2011:10:59:28 +0000] [localhost/sid#10090f128][rid#1009918a8/initial] (1) [perdir /WebServer/Documents/] pass through /WebServer/Documents/566432
你几乎做到了!
你忘了“%”!
和^(.*)$单独是(.*)相同,所以这里应该工作:
RewriteEngine On RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -f RewriteRule (.*) %{DOCUMENT_ROOT}/$1 [L] RewriteCond %{DOCUMENT_ROOT}/main2/%{REQUEST_FILENAME} -f RewriteRule (.*) %{DOCUMENT_ROOT}/main2/$1 [L]
告诉我,如果它的工作;)