2010-04-16 84 views
2

因此,我有一系列重定向,希望重定向到他們的父目錄(例如/ faq/question1/- >/faq /),但它非常不靈活,因爲它們是手動生成的。如何使用mod_rewrite將子頁面/目錄重定向到父目錄?

我該如何爲此設置RegEx燃料RewriteRule?我一直無法弄清楚,並會非常喜歡一些指導。這裏是我的整個的.htaccess的,以避免任何衝突(你可以看到個別RewriteRules我在的地方現在):

AddDefaultCharset utf-8 
AddHandler php5-script .php 
DirectoryIndex index.php 

ErrorDocument 403 /errors/forbidden.html 
ErrorDocument 500 /errors/internalerror.html 

<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteBase/
RewriteCond %{HTTP_HOST} ^halftoneproductions.com 
RewriteRule (.*) http://www.halftoneproductions.com/$1 [R=301,L] 

# FAQ redirects 
RewriteRule ^faq/how-much-does-it-cost-to-make-an-albummix-a-songetc /faq/ [R=301,L] 
RewriteRule ^faq/im-a-singersongwriter-with-no-band-members-would-you-be-able-to-do-a-full-production-of-my-songs-with-session-musicians /faq/ [R=301,L] 
RewriteRule ^faq/do-you-do-postsound-for-film-at-all /faq/ [R=301,L] 
RewriteRule ^faq/i-have-a-home-studio-and-just-need-to-record-___-is-that-cool /faq/ [R=301,L] 
RewriteRule ^faq/are-you-a-publishing-company /faq/ [R=301,L] 
RewriteRule ^faq/do-you-need-any-interns-or-runners /faq/ [R=301,L] 
RewriteRule ^faq/can-i-bring-my-own-producerengineer-to-a-session /faq/ [R=301,L] 
RewriteRule ^faq/what-types-of-music-do-you-work-on /faq/ [R=301,L] 
RewriteRule ^faq/do-you-work-with-languages-other-than-english /faq/ [R=301,L] 
RewriteRule ^faq/do-you-guys-make-beats /faq/ [R=301,L] 
RewriteRule ^faq/i-have-an-old-tape-reelcasetteminidiscetc-and-would-love-to-transfer-it-to-some-other-form-can-you-help-out /faq/ [R=301,L] 
RewriteRule ^faq/i-have-my-own-producerengineeretc-and-just-need-help-working-out-a-budget-for-my-project-and-booking-studio-time-can-you-help-out /faq/ [R=301,L] 

# Recent Work redirects 
RewriteRule ^recent-work/josh-and-neal /recent-work/ [R=301,L] 
RewriteRule ^recent-work/midnights-son /recent-work/ [R=301,L] 
RewriteRule ^recent-work/bearkat /recent-work/ [R=301,L] 
RewriteRule ^recent-work/madi-diaz /recent-work/ [R=301,L] 
</IfModule> 

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

回答

5

如果你想重定向的URL路徑具有/faq/作爲前綴的所有請求,您可以使用此規則:

RewriteRule ^faq/. /faq/ [R=301,L] 

單個.表示任意字符。因此,每個URL路徑請求都以/faq/開頭,後面至少有一個字符會重定向到/faq/

+0

Gumbo,非常感謝你。我對此感到頭痛,這讓我發瘋。我有一些東西接近於此,但它導致/ faq /本身的重定向循環。總是那些簡單的東西... – jeffbyrnes 2010-04-16 17:42:54

+0

爲了找到這個解決方案而搜索得很遠,沒有其他的工作,謝謝!拯救生命:) – ByteMyPixel 2017-08-22 19:52:48

相關問題