你好,我試圖完成下面所有的index.php失敗即使有一個與url相同的目錄。假設我有一個名爲'users'的文件夾,我不想讓'http://local.dev/users'將文件重定向到該文件夾,而是像其他請求一樣通過php來處理它。htaccess的重寫時,具有相同名稱的目錄存在
3)我想能夠訪問任何類型的圖像,js,css和其他特定文件類型 ,即使它們在目錄中。
我到目前爲止是這樣的:
RewriteEngine on
RewriteBase/
RewriteRule ^(.*)/$ $1 [R=301,L]
RewriteCond %{REQUEST_URI} !^.*\.(png|jpg|jpeg|bmp|gif|css|js|json|csv)$ [NC]
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]
和PHP測試案例:
<!DOCTYPE html>
<html>
<head>
<title>+dev</title>
</head>
<body>
<?php
echo $_SERVER['REQUEST_URI'] . '<br>';
print_r($_GET);
echo '<br>';
include 'test/test.php';
?>
<img src="/image.jpg">
<img src="/test/image2.jpg">
</body>
</html>
不過,我注意到了以下問題:
請記住,我有一個在htaccess和index.php旁邊的根目錄中名爲test的文件夾
http://local.dev/test/image.jpg =工作
http://local.dev/somestring =工作
http://local.dev/someImage.jpg =工作
http://local.dev/test = 2的情況下最後失敗
瀏覽器的URL輸出:
http://local.dev/test?path=test&path=test&path=test&path=test&path=test&path=test&path=test&path=test&path=test&path=test
Yeap重定向循環,但我不明白爲什麼,因爲我不熟悉mod_rewrite。我想要的是,最後2個失敗的請求被視爲純文本請求,無論是否存在具有相同名稱的文件夾。儘管我希望文件夾內的文件在擴展名位於「允許列表」中時可以訪問。
我看到,雖然它的工作原理的圖像加載失敗這樣 – Syd
什麼消息,你看到的圖片?另外,考慮啓用RewriteLog和RewriteLogLevel調試重寫規則爲圖像和pastebin執行的操作,並在此處發佈調試日誌。請參閱:https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog – Rijndael