基本上我想匹配文件路徑下面的文件路徑的任何模式,直到文件名,甚至文件沒有擴展名。.htaccess正則表達式匹配文件擴展名或無擴展名
我幾乎到了那裏,但是一旦我嘗試使它與沒有擴展名的文件相匹配,它就會匹配到該行的其餘部分。
我的測試字符串
http://regexr.com/foo.html?test (//regexr.com/foo.html)
http://regexr.com/foo?test (//regexr.com/foo)
http://regexr.com/foo.php?test (//regexr.com/foo.htm)
http://regexr.com/foo.htm?test (//regexr.com/foo.htm)
我現在的表情是\/(.+)\.php
但這並不沒有擴展匹配第二個文件路徑,如果我做了最後收集可選的,它選擇通過GET參數。任何幫助將非常感激。
編輯下面是我試圖修改
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \ /(.+)(\.php|\.html?)
RewriteRule^/%1.aspx [L,R=301]
RewriteRule ^(.*).aspx$ $1.php [QSA]
進一步編輯 正如指出的那樣,這可能是更好的要求作爲我的.htaccess塊重定向問題。 (另外,我刪除了html重定向,因爲它會導致性能下降,所以擴展名爲*.php
的文件是唯一被重定向的文件。)
這些是我想如何處理這些文件; 301重定向到新的地址,然後繼續被服務器處理爲PHP這樣:
http://regexr.com/foo.html (Doesn't redirect, not processed)
http://regexr.com/foo (R to /foo.aspx, processed as /foo.php)
http://regexr.com/foo.php (R to /foo.aspx, processed as /foo.php)
http://regexr.com/foo.htm (Doesn't redirect, not processed)
http://regexr.com/foo.aspx (Doesn't redirect, processed as /foo.php)
你能顯示你的規則嗎? – anubhava 2015-04-01 15:05:02
我可以,不知道這可能有什麼幫助,但我會盡快更新我的答案 – 2015-04-01 15:07:54