2014-01-09 30 views
0

使用此代碼:阿帕奇VirtualHosts - 排除多個文件,並從域中夾重定向

RedirectMatch 301 ^((?!.*?excluded_file\.php).*)$ http://newdomain.com$1 

...我目前正在重定向到我的Apache服務器的所有請求從olddomain.com到newdomain.com,除了爲一個名爲excluded_file.php的文件。但我實際上需要排除以「excluded_」開頭的所有文件(excluded_1.php,excluded_2.php,excluded_3.php)以及對文件夾「olddomainfiles」中的文件的任何請求。所以,最終的結果是:

會重定向到newdomain.com/whatevertherequestwasfor:

http://olddomain.com/somerandomfile.php 
http://olddomain.com/otherfolders/whateverfile.php 
http://olddomain.com/nice_URL_without_file_extension_or_slash 

不會重定向:

http://olddomain.com/olddomainfiles/anyfile.php 
http://olddomain.com/exclude_1.php 
http://olddomain.com/exclude_2.php 
http://olddomain.com/exclude_3.php 

爲什麼我需要這樣的:我剛剛提交了我蘋果的應用程序,並決定在最後一刻,我需要更改域名,這打破了應用程序的一個功能,因爲它明確依賴於看到舊的域名 - 它確實由於對我的虛擬主機文件所做的更改,不再看到它。前幾天我發佈了這個問題,但我錯了我需要的東西...

回答

1

這不工作?

RedirectMatch 301 ^((?!.*?(excluded.*\.php|olddomainfiles)).*)$ http://newdomain.com$1 

只是需要提前變消極的樣子(這是在尋找excluded_file\.php前中)爲excluded.*\.phpolddomainfiles的選擇。

+0

完美! 'excluded。* \。php'增加了一個下劃線,效果很好!謝謝! – tylerl