我已經有一些麻煩以下工作:國防部改寫成子目錄
<IfModule mod_rewrite.c>
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
# If the file is not found in web
RewriteCond web/$1 -f [NC] #<-- This line seems to be the problem.
RewriteRule ^(.*)$ web/$1 [L]
# Then rewrite it to index.php
RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
的想法是,以檢查文件中的web目錄存在,如果沒有,將請求路由到index.php。
上面的問題行似乎拿起了正確的URL,但它不能識別該文件存在。
例如:
http://localhost/img.gif --> /www/web/img.gif
http://localhost/subdir/file.doc --> /www/web/subdir/file.doc
http://localhost/user/add --> /www/index.php
http://localhost/invalidurl --> /www/index.php
但是,我不能讓被服務的靜態資源正確,他們都路由到index.php文件。
我也想保留所有的URL相對;所以我可以在不編輯它的情況下使此代碼可重用。
下面的.htaccess給出了一個內部服務器錯誤,如果我訪問img.gif:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
# If the file is not found in web
#RewriteCond web/$1 -f [NC] #<-- This line seems to be the problem.
RewriteRule ^(.*)$ web/$1 [L]
# Then rewrite it to index.php
#RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
這的.htaccess重定向到http://localhost/C:/absolute/path/to/web/img.gif,參觀img.gif時:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
# If the file is not found in web
#RewriteCond web/$1 -f [NC] #<-- This line seems to be the problem.
RewriteRule ^(.*)$ web/$1 [R]
# Then rewrite it to index.php
#RewriteRule ^(.*)$ index.php [L,QSA]
</IfModule>
我的結論從這將是它正在獲得路徑正確,但一些奇怪的是導致它做一些奇怪的事情(我甚至不知道它爲什麼有一個內部服務器錯誤 - 應該404找不到)。
請給我一些建議。 – xaav 2011-04-16 22:09:41
哇。這是我第一次沒有得到答案。 – xaav 2011-04-18 01:39:43
「靜態資源」是什麼意思? – 2011-04-18 10:24:45