views:

100

answers:

1

So I have a whole series of redirects in place for a bunch of pages I want redirected to their parent directory (e.g. /faq/question1/ -> /faq/), but it's very inflexible, as they're manually generated.

How can I set up a RegEx-fueled RewriteRule for this? I haven't been able to figure it out, and would dearly love some guidance. Here's the whole of my .htaccess, to avoid any conflicts (you can see the individual RewriteRules I have in place right now):

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
+2  A: 

If you want to redirect all requests that’s URL paths have /faq/ as prefix, you can use this rule:

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

The single . represents an arbitrary character. So every request that’s URL path starts with /faq/ that followed by at least one character is redirected to /faq/.

Gumbo
berkleebassist