2011-05-10 25 views
2

我有這樣的電流表達,這是需要site.com/index.phpsite.com/indexhtaccess的正則表達式與文件名兩個時期

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

我需要使其接受文件名與他們兩個時期,像site.com/core.index.phpsite.com/core.index

任何幫助,將不勝感激!

+0

嘗試'重寫規則^(+)(\ [^ \。] +)$ $ 1.PHP [? NC,L]' – Orbling 2011-05-10 06:22:27

+0

我猜'index.php'不應該被重定向到'index.php.php'? – Jens 2011-05-10 06:23:38

+0

爲了避免這種情況,我們應該使用!-f而不是!-d – gaRex 2011-05-10 13:49:12

回答

0

更簡單的解決方案可供選擇:

RewriteEngine on 
RewriteCond %{SCRIPT_FILENAME} !-f # We don`t have such file (includes !-d) 
RewriteRule ^(.*)$ $1.php [NC,L]  # Just add .php to the end 
1

正則表達式匹配^(.*)(?<!\.php)$每個地址不是以 「.PHP」 結尾,所以

RewriteRule ^(.*)(?<!\.php)$ $1.php [NC,L] 

可以工作。雖然我不熟悉RewriteRule。

+0

我確認 - 它的工作原理。 – gaRex 2011-05-10 13:44:48

0

使用這個表達式^[\w\d]*\.[\w\d]*\/[\w\d]*\.[\w\d]* enter image description here

+0

該解決方案不如第1和第3個有用。它就像硬編碼的東西,並不總是會捕捉所有可能的選項。 – gaRex 2011-05-10 13:48:22