2014-02-27 42 views
0

以下是我在我的.htaccess文件的.htaccess重寫規則的位數不工作,只有

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 

RewriteRule ^.*$ ./index.php 

這重定向任何不存在的目錄要求我的索引頁。這適用於www.site.com/AAAwww.site.com/A1www.site.com/1A,但不www.site.com/1www.site.com/123

基本上,它不會爲那些只有數字請求工作。

任何想法都將不勝感激。

我也試過

RewriteRule ^[0-9]*$ ./index.php 

但是,這並不工作。

我有Google作爲我的默認搜索引擎,所以當我輸入www.site.com/1234,並且找不到該頁面時,我將其導向Google搜索結果頁面,其中顯示「您的搜索與www.site.com/1234不匹配任何文件「 - 我認爲這與404相同,但Google接管並將其視爲搜索。

編輯 沒有發生在我身上這可能是一個瀏覽器問題。現在我嘗試了FF Mac和IE Win,並且它能正常工作。在Safari Mac或Safari iOS上無法正常工作。我只是把鏈接發送給更多的人去嘗試。

+0

您尚未嘗試僅通過顯示的內容使其僅適用於更具體的URI。你有沒有嘗試過這個? –

+0

這是唯一的規則還是你有更多的規則呢? – anubhava

+0

這就是.htaccess文件中的所有內容 – Chris

回答

0

我只是用你的默認虛擬主機的一個空的.htaccess規則,要求這

http://test.local/1 

,這是該請求

127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (3) [perdir /mnt/webs/test/] strip per-dir prefix: /mnt/webs/test/1 -> 1 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (3) [perdir /mnt/webs/test/] applying pattern '^.*$' to uri '1' 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (2) [perdir /mnt/webs/test/] rewrite '1' -> './index.php' 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (3) [perdir /mnt/webs/test/] add per-dir prefix: ./index.php -> /mnt/webs/test/./index.php 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (2) [perdir /mnt/webs/test/] strip document_root prefix: /mnt/webs/test/./index.php -> /./index.php 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c002970/initial] (1) [perdir /mnt/webs/test/] internal redirect with /./index.php [INTERNAL REDIRECT] 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c00be98/initial/redir#1] (3) [perdir /mnt/webs/test/] strip per-dir prefix: /mnt/webs/test/index.php -> index.php 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c00be98/initial/redir#1] (3) [perdir /mnt/webs/test/] applying pattern '^.*$' to uri 'index.php' 
127.0.0.1 - - [28/Feb/2014:10:31:14 +0800] [test.local/sid#a89a80][rid#7fc63c00be98/initial/redir#1] (1) [perdir /mnt/webs/test/] pass through /mnt/webs/test/index.php 

我得到了指數rewrite.log。 PHP文件。它應該工作

雖然,未成年人的建議是要改變這種

RewriteRule ^.*$ ./index.php 

這個

RewriteRule ^.*$ index.php 

是不是在你的代碼一個大的變化,但它消除了對服務器的一個內部一步因爲它不需要解析'./'部分。

一兩件事你可以做,以確認預期,事情正在努力,是有與眼前這個index.php文件:

var_dump($_SERVER); 

在那裏,你應該可以看到這個位

'REDIRECT_URL' => string '/1' (length=2) 
'REQUEST_URI' => string '/1' (length=2) 
'SCRIPT_NAME' => string '/index.php' (length=10) 

這將意味着請求是/ 1,但正在執行的文件是index.php,這意味着重寫工作。如果你得到不同的東西,它是調試

+0

我明白它可以在您的服務器上運行,但它不適用於我的服務器。我收到一條「Not Found」消息,並將其重定向到一個Google頁面,當頁面不存在時,我認爲這只是瀏覽器的默認默認操作。 – Chris

+0

這不是應該發生的事情。你有一些做重定向。檢查訪問和重寫日誌並檢查發生了什麼。清除日誌,重新啓動服務器並嘗試加載以/ 1結尾的URL,然後加載其他任何內容。完成之後,在這裏發佈兩個日誌(訪問和重寫)。檢查你的主機文件。未找到的 – PatomaS

+0

顯示在瀏覽器上?那麼你會自動重定向?這是否發生在多個瀏覽器中? – PatomaS

0

開始嘗試使用

FallbackResource /index.php

代替並刪除重寫規則。據報道,它與Apache 2.2一起工作。16+(我沒有用數字測試,但值得一試)。

+0

這仍然給我同樣的結果。使用所有數字會將我推到一個Google頁面,其中顯示「您搜索的內容與任何文檔都不匹配」 - 所有其他結果與我原始文章中的相同。 – Chris

+0

聽起來像您的瀏覽器的「Omnibox」可能是錯誤的。如果輸入包括協議在內的地址會發生什麼?例如'http:// www.example.com/1234' – contrebis

+0

啊,這是行得通......並不是我想要的解決方案,但也許這就是它的需要? – Chris