1
我的.htaccess文件看起來是這樣的:Apache .htaccess的行爲奇怪嗎?
#Options FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([a-zA-Z0-9\-\/]*[a-zA-Z0-9])$ index.php?_path=$1&%1
這裏是我的文件結構:
example.com/
|- rewriteTest/
| |- images/
| | |- logo.png
| | |- icon.png
| |- style/
| | |- housekeeping.css
| | |- style.css
| |- .htaccess
| |- index.php
期望的行爲是
example.com/rewriteTest/any/path
應指向
example.com/rewriteTest/index.php?_path=any/path
和
example.com/rewriteTest/images
(不帶前導斜槓)應指向
example.com/rewriteTest/index.php?_path=images
和
example.com/rewriteTest/images/logo.png
應指向
example.com/rewriteTest/index.php?_path=images/logo.png
重寫作品,如果路徑I不是現有的目錄或文件。但是,如果我導航至/images
目錄,則瀏覽器中的網址(Chrome)會更改爲/images/?_path=images
,並顯示403頁。如果我導航到/images/logo.png
,圖像打開,而不是在/index.php?_path=images/logo.png
顯示頁面。
爲什麼會發生這種情況,我該如何解決這個問題?
這是行不通的。現在我得到了任何URL的403 Forbidden。我不確定正則表達式是否是問題,因爲它適用於其他任何事情。我的問題是,當我導航到實際存在的路徑時,似乎mod_rewrite會中斷。 – hugabor
取消註釋'選項FollowSymLinks'使我的index.php由於某種原因變爲禁止。 – hugabor
'.htaccess'位於圖像的父目錄中,並與'index.php'一起。 – hugabor