2

I have close to 200 redirects that I would I to bring down to maybe a few dozen. Most look like the following.

Redirect permanent /Fandom/Fictional_artifacts.pl /Fandom/index.pl?page=Fictional+artifacts

I would have it already if the underscores in the file name didn't need to be turned into plus signs, however, the underscores will need to be altered and that is where I get stuck.

RedirectMatch permanent /Fandom/(.*).pl /Fandom/index.pl?page=$1 # Needs underscores converted still

I also have links that need to be redirected to a new page and a new parameter. However, I tried the following, and it ignores the new parameter name.

Redirect permanent /Movies/Movies_by_genre.pl?genre=action /Movies/index.pl?genre+list=action

And I was hoping to combine all of the genres into one line.

RedirectMatch permanent /Movies/Movies_by_genre.pl?genre=(.*) /Movies/index.pl?genre+list=$1

I am hoping to bring the following long list down to something more manageable.

Redirect permanent /about.pl                        /index.pl?page=about
Redirect permanent /Collections/Fiction.pl          /Collections/index.pl?page=Fiction
Redirect permanent /Collections/Movies/pl           /Collections/index.pl?page=Movie # Also made singular
Redirect permanent /Collections/Music_and_Comedy.pl /Collections/index.pl?page=Music+and+Comedy
Redirect permanent /Collections/Non-fiction.pl      /Collections/index.pl?page=Non-fiction
Redirect permanent /Collections/Programs.pl         /Collections/index.pl?page=Program # Also made singular
Redirect permanent /Collections/Role_playing.pl     /Collections/index.pl?page=Role+playing
Redirect permanent /Collections/Tie-ins.pl          /Collections/index.pl?page=Tie-in # Also made singular
Redirect permanent /Fandom/The_Belgariad_and_Malloreon.pl                              /Fandom/index.pl?page=The+Belgariad+and+Malloreon
Redirect permanent /Fandom/Camelot_on_ISCA.pl                                          /Fandom/index.pl?page=Camelot+on+ISCA
Redirect permanent /Fandom/Fictional_artifacts.pl                                      /Fandom/index.pl?page=Fictional+artifacts
Redirect permanent /Fandom/Fictional_secret_societies.pl                               /Fandom/index.pl?page=Fictional+secret+societies
Redirect permanent /Fandom/Magical_worlds.pl                                           /Fandom/index.pl?page=Magical+worlds
Redirect permanent /Fandom/Crossovers/General_crossovers.pl                            /Fandom/Crossovers/index.pl?page=General+crossovers
Redirect permanent /Fandom/Crossovers/Horror_crossovers.pl                             /Fandom/Crossovers/index.pl?page=Horror+crossovers
Redirect permanent /Fandom/Crossovers/Big_fake_companies/Morley.pl                     /Fandom/Crossovers/Big_fake_companies/index.pl?page=Morley
Redirect permanent /Fandom/Crossovers/Big_fake_companies/Oceanic_Airlines.pl           /Fandom/Crossovers/Big_fake_companies/index.pl?page=Oceanic+Airlines
Redirect permanent /Fandom/Crossovers/Westphall_crossovers/Arriving_in_Westphall.pl    /Fandom/Crossovers/Westphall_crossovers/index.pl?page=Arriving+in+Westphall
Redirect permanent /Fandom/Crossovers/Westphall_crossovers/Departing_from_Westphall.pl /Fandom/Crossovers/Westphall_crossovers/index.pl?page=Departing+from+Westphall
Redirect permanent /Fandom/Crossovers/Westphall_crossovers/Trimmed_from_Westphall.pl   /Fandom/Crossovers/Westphall_crossovers/index.pl?page=Trimmed+from+Westphall
Redirect permanent /Fandom/Crossovers/Westphall_crossovers/Westerns_in_Crisis.pl       /Fandom/Crossovers/Westphall_crossovers/index.pl?page=Westerns+in+Crisis
Redirect permanent /Fandom/Fictional_family_trees/Avengers_family_trees.pl             /Fandom/Fictional_family_trees/index.pl?page=Avengers+family+trees
Redirect permanent /Fandom/Fictional_family_trees/Bones_family_trees.pl                /Fandom/Fictional_family_trees/index.pl?page=Bones+family+trees
Redirect permanent /Fandom/Fictional_family_trees/Castle_family_trees.pl               /Fandom/Fictional_family_trees/index.pl?page=Castle+family+trees
Redirect permanent /Fandom/Fictional_family_trees/Chuck_family_trees.pl                /Fandom/Fictional_family_trees/index.pl?page=Chuck+family+trees
Redirect permanent /Fandom/Fictional_family_trees/Gilmore_Girls_family_trees.pl        /Fandom/Fictional_family_trees/index.pl?page=Gilmore+Girls+family+trees
Redirect permanent /Fandom/Fictional_family_trees/Hart_of_Dixie_family_trees.pl        /Fandom/Fictional_family_trees/index.pl?page=Hart+of+Dixie+family+trees
Redirect permanent /Fandom/The_Riftwar/Kelewan.pl                                      /Fandom/The_Riftwar/index.pl?page=Kelewan
Redirect permanent /Fandom/The_Riftwar/Midkemia.pl                                     /Fandom/The_Riftwar/index.pl?page=Midkemia
Redirect permanent /Fandom/Xanth/Families.pl                                           /Fandom/Xanth/index.pl?page=Families
Redirect permanent /Fandom/Xanth/Kings.pl                                              /Fandom/Xanth/index.pl?page=Kings
Redirect permanent /Fandom/Xanth/Locations.pl                                          /Fandom/Xanth/index.pl?page=Locations
Redirect permanent /Fandom/Xanth/Species.pl                                            /Fandom/Xanth/index.pl?page=Species
Redirect permanent /Fandom/Xanth/Timeline.pl                                           /Fandom/Xanth/index.pl?page=Timeline
Redirect permanent /Miscellany/Awareness_tests.pl                             /Miscellany/index.pl?page=Awareness+tests
Redirect permanent /Miscellany/BBSs.pl                                        /Miscellany/index.pl?page=BBSs
Redirect permanent /Miscellany/Genre.pl                                       /Miscellany/index.pl?page=Genre
Redirect permanent /Miscellany/IRC_channels_I_visit.pl                        /index.pl?page=irc
Redirect permanent /Miscellany/Jokes_I_found_funny.pl                         /Miscellany/index.pl?page=Jokes+I+found+funny
Redirect permanent /Miscellany/Learning_HTML.pl                               /Miscellany/index.pl?page=Learning+HTML
Redirect permanent /Miscellany/Random_orgy_generator.pl                       /Miscellany/index.pl?page=Random+orgy+generator
Redirect permanent /Miscellany/Use_of_language.pl                             /Miscellany/index.pl?page=Use+of+language
Redirect permanent /Miscellany/What_I_find_sexy.pl                            /Miscellany/index.pl?page=What+I+find+sexy
Redirect permanent /Miscellany/Geeky_thoughts/Chess_variants.pl               /Miscellany/Geeky_thoughts/index.pl?page=Chess+variants
Redirect permanent /Miscellany/Geeky_thoughts/Geek_codes.pl                   /Miscellany/Geeky_thoughts/index.pl?page=Geek+codes
Redirect permanent /Miscellany/Geeky_thoughts/Living_in_an_underwater_dome.pl /Miscellany/Geeky_thoughts/index.pl?page=Living+in+an+underwater+dome
Redirect permanent /Miscellany/Geeky_thoughts/Numeration_scale.pl             /Miscellany/Geeky_thoughts/index.pl?page=Numeration+scale
Redirect permanent /Miscellany/Geeky_thoughts/Rules_of_space_travel.pl        /Miscellany/Geeky_thoughts/index.pl?page=Rules+of+space+travel
Redirect permanent /Miscellany/Political_opinions/Drugs_and_alcohol.pl        /Miscellany/Political_opinions/index.pl?page=Drugs+and+alcohol
Redirect permanent /Miscellany/Political_opinions/Population_control.pl       /Miscellany/Political_opinions/index.pl?page=Population+control
Redirect permanent /Miscellany/Political_opinions/The_Second_Amendment.pl     /Miscellany/Political_opinions/index.pl?page=The+Second+Amendment
Redirect permanent /Movies/Movies_by_genre.pl                                          /Movies/index.pl?genre+list=list
Redirect permanent /Movies/Movies_by_genre.pl?genre=action                             /Movies/index.pl?genre+list=action
Redirect permanent /Movies/Movies_by_genre.pl?genre=adventure                          /Movies/index.pl?genre+listadventure
Redirect permanent /Movies/Movies_by_genre.pl?genre=animated                           /Movies/index.pl?genre+listanimated
Redirect permanent /Movies/Movies_by_genre.pl?genre=anthology                          /Movies/index.pl?genre+listanthology
Redirect permanent /Movies/Movies_by_genre.pl?genre=award show                         /Movies/index.pl?genre+list=award show
Redirect permanent /Movies/Movies_by_genre.pl?genre=comedy                             /Movies/index.pl?genre+list=comedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=contest                            /Movies/index.pl?genre+list=contest
Redirect permanent /Movies/Movies_by_genre.pl?genre=crime                              /Movies/index.pl?genre+list=crime
Redirect permanent /Movies/Movies_by_genre.pl?genre=detective                          /Movies/index.pl?genre+list=detective
Redirect permanent /Movies/Movies_by_genre.pl?genre=disaster                           /Movies/index.pl?genre+list=disaster
Redirect permanent /Movies/Movies_by_genre.pl?genre=docudrama                          /Movies/index.pl?genre+list=docudrama
Redirect permanent /Movies/Movies_by_genre.pl?genre=drama                              /Movies/index.pl?genre+list=drama
Redirect permanent /Movies/Movies_by_genre.pl?genre=dramedy                            /Movies/index.pl?genre+list=dramedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=erotica                            /Movies/index.pl?genre+list=erotica
Redirect permanent /Movies/Movies_by_genre.pl?genre=fantasy                            /Movies/index.pl?genre+list=fantasy
Redirect permanent /Movies/Movies_by_genre.pl?genre=gothic                             /Movies/index.pl?genre+list=gothic
Redirect permanent /Movies/Movies_by_genre.pl?genre=horror                             /Movies/index.pl?genre+list=horror
Redirect permanent /Movies/Movies_by_genre.pl?genre=legal                              /Movies/index.pl?genre+list=legal
Redirect permanent /Movies/Movies_by_genre.pl?genre=medical                            /Movies/index.pl?genre+list=medical
Redirect permanent /Movies/Movies_by_genre.pl?genre=military                           /Movies/index.pl?genre+list=military
Redirect permanent /Movies/Movies_by_genre.pl?genre=monster                            /Movies/index.pl?genre+list=monster
Redirect permanent /Movies/Movies_by_genre.pl?genre=music                              /Movies/index.pl?genre+list=music
Redirect permanent /Movies/Movies_by_genre.pl?genre=musical                            /Movies/index.pl?genre+list=musical
Redirect permanent /Movies/Movies_by_genre.pl?genre=mystery                            /Movies/index.pl?genre+list=mystery
Redirect permanent /Movies/Movies_by_genre.pl?genre=non-fiction                        /Movies/index.pl?genre+list=non-fiction
Redirect permanent /Movies/Movies_by_genre.pl?genre=parody                             /Movies/index.pl?genre+list=parody
Redirect permanent /Movies/Movies_by_genre.pl?genre=police procedural                  /Movies/index.pl?genre+list=police procedural
Redirect permanent /Movies/Movies_by_genre.pl?genre=post-apocalypse                    /Movies/index.pl?genre+list=post-apocalypse
Redirect permanent /Movies/Movies_by_genre.pl?genre=romantic comedy                    /Movies/index.pl?genre+list=romantic comedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=romantic drama                     /Movies/index.pl?genre+list=romantic drama
Redirect permanent /Movies/Movies_by_genre.pl?genre=romantic dramedy                   /Movies/index.pl?genre+list=romantic dramedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=science fantasy                    /Movies/index.pl?genre+list=science fantasy
Redirect permanent /Movies/Movies_by_genre.pl?genre=science fiction                    /Movies/index.pl?genre+list=science fiction
Redirect permanent /Movies/Movies_by_genre.pl?genre=science fiction western            /Movies/index.pl?genre+list=science fiction western
Redirect permanent /Movies/Movies_by_genre.pl?genre=situation comedy                   /Movies/index.pl?genre+list=situation comedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=slasher                            /Movies/index.pl?genre+list=slasher
Redirect permanent /Movies/Movies_by_genre.pl?genre=speculative fiction                /Movies/index.pl?genre+list=speculative fiction
Redirect permanent /Movies/Movies_by_genre.pl?genre=spoof                              /Movies/index.pl?genre+list=spoof
Redirect permanent /Movies/Movies_by_genre.pl?genre=sports                             /Movies/index.pl?genre+list=sports
Redirect permanent /Movies/Movies_by_genre.pl?genre=spy                                /Movies/index.pl?genre+list=spy
Redirect permanent /Movies/Movies_by_genre.pl?genre=spy fiction                        /Movies/index.pl?genre+list=spy fiction
Redirect permanent /Movies/Movies_by_genre.pl?genre=stand-up comedy                    /Movies/index.pl?genre+list=stand-up comedy
Redirect permanent /Movies/Movies_by_genre.pl?genre=steampunk                          /Movies/index.pl?genre+list=steampunk
Redirect permanent /Movies/Movies_by_genre.pl?genre=superhero fiction                  /Movies/index.pl?genre+list=superhero fiction
Redirect permanent /Movies/Movies_by_genre.pl?genre=talk show                          /Movies/index.pl?genre+list=talk show
Redirect permanent /Movies/Movies_by_genre.pl?genre=thriller                           /Movies/index.pl?genre+list=thriller
Redirect permanent /Movies/Movies_by_genre.pl?genre=variety                            /Movies/index.pl?genre+list=variety
Redirect permanent /Movies/Movies_by_genre.pl?genre=war                                /Movies/index.pl?genre+list=war
Redirect permanent /Movies/Movies_by_genre.pl?genre=western                            /Movies/index.pl?genre+list=western
Redirect permanent /Role_playing/Locations/Drianna's_Citadel_of_Magical_Creation.pl        /Role_playing/Locations/index.pl?page=Drianna's+Citadel+of+Magical+Creation
Redirect permanent /Role_playing/Locations/Olakeen.pl                                      /Role_playing/Locations/index.pl?page=Olakeen
Redirect permanent /Role_playing/Locations/The_Schools_of_Magic.pl                         /Role_playing/Locations/index.pl?page=The+Schools+of+Magic
Redirect permanent /Role_playing/Locations/The_True_Void.pl                                /Role_playing/Locations/index.pl?page=The+True+Void
Redirect permanent /Role_playing/Locations/Afma/Aleena.pl                                  /Role_playing/Locations/Afma/index.pl?page=Aleena
Redirect permanent /Role_playing/Locations/Afma/Aleenia.pl                                 /Role_playing/Locations/Afma/index.pl?page=Aleenia
Redirect permanent /Role_playing/Magic_items/Apparatus.pl                                  /Role_playing/Magic_items/index.pl?page=Apparatus
Redirect permanent /Role_playing/Magic_items/Armor.pl                                      /Role_playing/Magic_items/index.pl?page=Armor
Redirect permanent /Role_playing/Magic_items/Bags_and_bottles.pl                           /Role_playing/Magic_items/index.pl?page=Bags+and+bottles
Redirect permanent /Role_playing/Magic_items/Books.pl                                      /Role_playing/Magic_items/index.pl?page=Books
Redirect permanent /Role_playing/Magic_items/Boots_and_gloves.pl                           /Role_playing/Magic_items/index.pl?page=Boots+and+gloves
Redirect permanent /Role_playing/Magic_items/Clothing.pl                                   /Role_playing/Magic_items/index.pl?page=Clothing
Redirect permanent /Role_playing/Magic_items/Gems_and_jewelry.pl                           /Role_playing/Magic_items/index.pl?page=Gems+and+jewelry
Redirect permanent /Role_playing/Magic_items/Girdles_and_helmets.pl                        /Role_playing/Magic_items/index.pl?page=Girdles+and+helmets
Redirect permanent /Role_playing/Magic_items/Magical_liquids.pl                            /Role_playing/Magic_items/index.pl?page=Magical+liquids
Redirect permanent /Role_playing/Magic_items/Miscellaneous.pl                              /Role_playing/Magic_items/index.pl?page=Miscellaneous
Redirect permanent /Role_playing/Magic_items/Rings.pl                                      /Role_playing/Magic_items/index.pl?page=Rings
Redirect permanent /Role_playing/Magic_items/Rods.pl                                       /Role_playing/Magic_items/index.pl?page=Rods
Redirect permanent /Role_playing/Magic_items/Scrolls.pl                                    /Role_playing/Magic_items/index.pl?page=Scrolls
Redirect permanent /Role_playing/Magic_items/Staves.pl                                     /Role_playing/Magic_items/index.pl?page=Staves
Redirect permanent /Role_playing/Magic_items/Wands.pl                                      /Role_playing/Magic_items/index.pl?page=Wands
Redirect permanent /Role_playing/Magic_items/Weapons.pl                                    /Role_playing/Magic_items/index.pl?page=Weapons
Redirect permanent /Role_playing/Magic_items/Weapons_of_the_Planes.pl                      /Role_playing/Magic_items/index.pl?page=Weapons+of+the+Planes
Redirect permanent /Role_playing/Miscellany/Adventure_ideas.pl                             /Role_playing/Miscellany/index.pl?page=Adventure+ideas
Redirect permanent /Role_playing/Miscellany/Chaos_warden.pl                                /Role_playing/Miscellany/index.pl?page=Chaos+warden
Redirect permanent /Role_playing/Miscellany/Creche_protectors.pl                           /Role_playing/Miscellany/index.pl?page=Creche+protectors
Redirect permanent /Role_playing/Miscellany/Daegen_Burough.pl                              /Role_playing/Miscellany/index.pl?page=Daegen+Burough
Redirect permanent /Role_playing/Miscellany/Languages_and_races.pl                         /Role_playing/Miscellany/index.pl?page=Languages+and+races
Redirect permanent /Role_playing/Miscellany/The_Seduction_of_Death.pl                      /Role_playing/Miscellany/index.pl?page=The+Seduction+of+Death
Redirect permanent /Role_playing/Monsters/The_Creation_of_Monsters.pl                      /Role_playing/Miscellany/index.pl?page=The+Creation+of+Monsters
Redirect permanent /Role_playing/Player_characters/House_rules.pl                          /Role_playing/Player_characters/index.pl?page=House+rules
Redirect permanent /Role_playing/Player_characters/Stories/Daughter_of_the_Vampire.pl      /Role_playing/Player_characters/Stories/index.pl?page=Daughter+of+the+Vampire
Redirect permanent /Role_playing/Player_characters/Stories/The_Outcasts.pl                 /Role_playing/Player_characters/Stories/index.pl?page=The+Outcasts
Redirect permanent /Role_playing/Player_characters/Stories/The_Sisters'_Dilemma.pl         /Role_playing/Player_characters/Stories/index.pl?page=The+Sisters'+Dilemma
Redirect permanent /Role_playing/Player_characters/Stories/The_Society_of_Divided_Light.pl /Role_playing/Player_characters/Stories/index.pl?page=The+Society+of+Divided+Light
Redirect permanent /Role_playing/Player_characters/Stories/The_Star_Tribe.pl               /Role_playing/Player_characters/Stories/index.pl?page=The+Star+Tribe
Redirect permanent /Role_playing/Player_characters/Stories/Two_Worlds.pl                   /Role_playing/Player_characters/Stories/index.pl?page=Two+Worlds
Redirect permanent /Role_playing/Reference_tables/Equipment_kits.pl                        /Role_playing/Reference_tables/index.pl?page=Equipment+kits
Redirect permanent /Role_playing/Reference_tables/Expanded_alignments.pl                   /Role_playing/Reference_tables/index.pl?page=Expanded+alignments
Redirect permanent /Role_playing/Reference_tables/Racial_special_abilities.pl              /Role_playing/Reference_tables/index.pl?page=Racial+special+abilities
Redirect permanent /Writing/One_sentence_stories.pl                        /Writing/index.pl?page=One+sentence+stories
Redirect permanent /Writing/Party.pl                                       /Writing/index.pl?page=Party
Redirect permanent /Writing/Recruiting_Day.pl                              /Writing/index.pl?page=Recruiting+Day
Redirect permanent /Writing/The_Lonely_Kitchen.pl                          /Writing/index.pl?page=The+Lonely+Kitchen
Redirect permanent /Writing/The_Sole_Caroler.pl                            /Writing/index.pl?page=The+Sole+Caroler
Redirect permanent /Writing/Erotic_fiction/The_Angel.pl                    /Writing/Erotic_fiction/index.pl?page=The+Angel
Redirect permanent /Writing/Erotic_fiction/The_Assassin.pl                 /Writing/Erotic_fiction/index.pl?page=The+Assassin
Redirect permanent /Writing/Erotic_fiction/Blind_Pleasure.pl               /Writing/Erotic_fiction/index.pl?page=Blind+Pleasure
Redirect permanent /Writing/Erotic_fiction/Diane's_Intimate_Life.pl        /Writing/Erotic_fiction/index.pl?page=Diane's+Intimate+Life
Redirect permanent /Writing/Erotic_fiction/Dixon's_Night.pl                /Writing/Erotic_fiction/index.pl?page=Dixon's+Night
Redirect permanent /Writing/Erotic_fiction/Domination_in_Boxers.pl         /Writing/Erotic_fiction/index.pl?page=Domination+in+Boxers
Redirect permanent /Writing/Erotic_fiction/Game_Controller.pl              /Writing/Erotic_fiction/index.pl?page=Game+Controller
Redirect permanent /Writing/Erotic_fiction/Love_in_Space.pl                /Writing/Erotic_fiction/index.pl?page=Love+in+Space
Redirect permanent /Writing/Erotic_fiction/The_Lover.pl                    /Writing/Erotic_fiction/index.pl?page=The+Lover
Redirect permanent /Writing/Erotic_fiction/Men_of_the_Night.pl             /Writing/Erotic_fiction/index.pl?page=Men+of+the+Night
Redirect permanent /Writing/Erotic_fiction/The_Pirate_and_the_Sorceress.pl /Writing/Erotic_fiction/index.pl?page=The+Pirate+and+the+Sorceress
Redirect permanent /Writing/Erotic_fiction/Submission_on_Station.pl        /Writing/Erotic_fiction/index.pl?page=Submission+on+Station
Redirect permanent /Writing/Erotic_fiction/Sweet_Agony.pl                  /Writing/Erotic_fiction/index.pl?page=Sweet+Agony
Redirect permanent /Writing/Erotic_fiction/The_Wolf.pl                     /Writing/Erotic_fiction/index.pl?page=The+Wolf
Redirect permanent /Writing/Erotic_fiction/Two_Windows.pl                  /Writing/Erotic_fiction/index.pl?page=Two+Windows
Redirect permanent /Writing/Fan_fiction/Necessary_Roughness.pl             /Writing/Fan_fiction/index.pl?page=Necessary+Roughness
Redirect permanent /Writing/Fan_fiction/Scarecrow_and_Mrs_King.pl          /Writing/Fan_fiction/index.pl?page=Scarecrow+and+Mrs+King
Redirect permanent /Writing/Poetry/Poems.pl                                /Writing/Poetry/index.pl?page=Poems
Redirect permanent /Writing/Poetry/Poems_of_Desire.pl                      /Writing/Poetry/index.pl?page=Poems+of+Desire
Redirect permanent /Writing/Poetry/Poems_of_Fear.pl                        /Writing/Poetry/index.pl?page=Poems+of+Fear
Redirect permanent /Writing/Poetry/Poems_of_Love.pl                        /Writing/Poetry/index.pl?page=Poems+of+Love
Redirect permanent /Writing/Poetry/Serious_Poems.pl                        /Writing/Poetry/index.pl?page=Serious+Poems
Redirect permanent /Writing/Poetry/Silly_Poems.pl                          /Writing/Poetry/index.pl?page=Silly+Poems
Redirect permanent /Writing/Poetry/Uncategorized_poems.pl                  /Writing/Poetry/index.pl?page=Uncategorized+poems

So, will these work as is? Is there a way to cut that list down with RedirectMatch?

10
  • 1
    RedirectMatch and other mod_alias directives don't look at the query string, so you can't redirect using them based on parameters. Are you willing to use mod_rewrite instead when needed? – Stephen Ostermiller Jun 19 '20 at 20:21
  • 1
    yes, rewrite rules usually go in .htaccess – Stephen Ostermiller Jun 19 '20 at 20:32
  • 1
    What is the reason for these redirects? Presumably, the "old" URL no longer exists and you are redirecting to the "new" URL in order to preserve SEO? If so, then it would be preferable to perform these redirects later in your application logic (when your 404 is triggered), rather than using Apache/.htaccess (which is unnecessarily processed on every request). (Although the "old" URLs looks more SEO-friendly - should these be redirects at all?!) – MrWhite Jun 19 '20 at 21:41
  • 1
    So, which URL you are linking to in your HTML source? eg. /about.pl or /index.pl?page=about? Are these redirects essential for your site to function? – MrWhite Jun 20 '20 at 20:10
  • 1
    "I believe personal sites like mine get shifted to the bottom" - there's no difference between personal sites and "commercial" sites, except in the additional leg work that a "commercial" site might put into marketing and building back links etc. (and maybe subject matter). "especially those which aren't written in a popular web framework." - the "web framework" doesn't really have anything to do with SEO - you can do all the necessary SEO stuff with or without a framework. – MrWhite Jun 20 '20 at 20:19
3

Since these "old" URLs no longer exist, it is arguably better (ie. more efficient) to perform these redirects late in your application logic, ie. when a 404 would otherwise be triggered, rather than early in .htaccess. This greatly reduces the number of times your redirect logic is processed - prioritising normal site visitors (since you are linking to the "new" URLs internally).

You could perhaps implement this with a custom 404 error document:

ErrorDocument 404 /error-handlers/404.pl

NB: If you use a separate .pl file (as above) then you will need to add another exception in the redirects below (since you don't want this redirected to /error-handlers/index.pl?page=404).

Your redirects would then be implemented in your 404.pl script.

Or perhaps go straight to /index.pl and implement this in your existing script.

ErrorDocument 404 /index.pl?page=404

Note that the error document is not exposed to the end-user. eg. When you request /about.pl, the error document is served via an internal subrequest.

UPDATE: However, this would be more critical if you had 1000's of individual redirects with no discernable pattern - the time processing the redirects could become significant. In this case, 200 is not too many - not enough to impact performance - and since these redirects can be condensed into "a handful" of directives, recognising the common patterns, performance is really a non-issue.

.htaccess / mod_rewrite

Redirect permanent /Movies/Movies_by_genre.pl?genre=action /Movies/index.pl?genre+list=action

None of these Redirect directives - that attempt to match against the query string - are doing anything. The mod_alias Redirect directive matches against the URL-path only (which notably excludes the query string), so these directives simply never match. However, you would also need to do something about the unencoded spaces in the target URL, as that's simply not valid (spaces are delimiters in Apache config files).

As @StephenOstermiller pointed out in comments, you will need to use mod_rewrite (RewriteRule and RewriteCond), as opposed to mod_alias (Redirect or RedirectMatch) to be able to examine requests that contain a query string. It is inadvisable to mix redirects from both modules, so everything needs to use mod_rewrite (even though some of these redirects could be handled by RedirectMatch or even Redirect).

You also seem to have several (of what I assume are) typos in your current set of redirects? For example:

Redirect permanent /Collections/Movies/pl /Collections/index.pl?page=Movie # Also made singular
:
Redirect permanent /Movies/Movies_by_genre.pl?genre=adventure /Movies/index.pl?genre+listadventure
Redirect permanent /Movies/Movies_by_genre.pl?genre=animated /Movies/index.pl?genre+listanimated
Redirect permanent /Movies/Movies_by_genre.pl?genre=anthology /Movies/index.pl?genre+listanthology

I assume that should be Movies.pl and ?genre+list=adventure etc. (?)

Additional note: line-end comments are not supported by Apache. You should only use full-line comments. (In fact, with a mod_alias Redirect, I would expect this to result in a 500 error! Sometimes line-end comments appear to "work", but that's not a feature, it's just a quirk of how some modules work.)

Aside: Using spaces (the encoded +) in URL parameter names is not particularly portable and generally best avoided if possible. I realise you are using Perl, but if (for instance) you decided to convert to PHP then PHP will automatically convert the space to an underscore in the $_GET array, so you would need to manually parse the URL to extract the URL params.

Redirect permanent /Miscellany/IRC_channels_I_visit.pl /index.pl?page=irc

You appear to have a number of "special cases", that don't necessarily fit a reliable pattern, including converting "some" URLs from plural to singular. These need to be processed first in order to avoid conflicting with the "general cases".

I assume the redirect above is just another "special case"? Although it seems out of place that you are also removing the /Miscellany subdirectory and redirecting to the root?

Redirect permanent /Movies/Movies_by_genre.pl?genre=award show

How are spaces URL encoded in the requested URL parameter value? award show is the URL-decoded value. With mod_rewrite we need to match against the URL-encoded value. In the case of the query string, this could be either %20 (%-encoded) or + (special case). It is easier to allow just +. For now, I'll permit both, but this has the caveat that it will allow any %-encoded character (you don't have any, except for a potential %20).

the underscores will need to be altered and that is where I get stuck.

Since I assume this is a finite list of redirects then you don't need to handle the general case of any number of underscores. I count a maximum of 4 (in the last path segment) in the directives you've posted, so you can hardcode the searches to 0, 1, 2, 3 or 4 underscores (5 directives). None begin or end with an underscore. If you need a more general solution then check out my answer to the following StackOverflow question:

Solution

Try something like the following in .htaccess using mod_rewrite. By my reckoning, this covers all 170 redirects as stated in your question.

RewriteEngine On

# If the request is already for `index.pl` then don't go any further
RewriteRule index\.pl$ - [L]

# Special case #1 - Make singular
RewriteRule ^([\w/]+/)?(Movie|Program|Tie-in)s\.pl$ /$1index.pl?page=$2 [R=301,L]

# Special case #2 - Unique / No pattern
RewriteRule ^Miscellany/IRC_channels_I_visit\.pl$ /index.pl?page=irc [R=301,L]

# General case #1 - "Movies_by_genre.pl"
RewriteCond %{QUERY_STRING} ^genre=([a-z+\%0-9]+)$
RewriteRule ^(Movies)/Movies_by_genre\.pl$ /$1/index.pl?genre+list=%1 [NE,R=301,L]
# No "genre" URL param with value
RewriteRule ^(Movies)/Movies_by_genre\.pl$ /$1/index.pl?genre+list=list [R=301,L]

# General case #2 - redirect to index.pl in the relevant directory
# One directive for each of 0, 1, 2, 3 or 4 underscores
RewriteRule ^([\w/]+/)?([a-z']+)\.pl$ /$1index.pl?page=$2 [NC,R=301,L]
RewriteRule ^([\w/]+/)?([a-z']+)_([a-z']+)\.pl$ /$1index.pl?page=$2+$3 [NC,R=301,L]
RewriteRule ^([\w/]+/)?([a-z']+)_([a-z']+)_([a-z]+)\.pl$ /$1index.pl?page=$2+$3+$4 [NC,R=301,L]
RewriteRule ^([\w/]+/)?([a-z']+)_([a-z']+)_([a-z]+)_([a-z]+)\.pl$ /$1index.pl?page=$2+$3+$4+$5 [NC,R=301,L]
RewriteRule ^([\w/]+/)?([a-z']+)_([a-z']+)_([a-z]+)_([a-z]+)_([a-z]+)\.pl$ /$1index.pl?page=$2+$3+$4+$5+$6 [NC,R=301,L]

Note that the URL-path matched by the RewriteRule pattern does not start with a slash, unlike mod_alias's Redirect and RedirectMatch directives.

The NE flag on the Movies_by_genre.pl?genre=<something> directive is required if %20 is being passed as the encoded space in the URL parameter value (browser default). This is not required if all spaces are encoded as + in the query string.

UPDATE: Four of your URLs/redirects contain apostrophes (') - but only in either of the first two parts between underscores. I've added these to the above regex character classes. Note that the RewriteRule pattern matches against the %-decoded URL-path. But the ' will likely be %-encoded as %27 by the browser in the redirected request when part of the query string.

It is advisable to first test with 302 (temporary) redirects in order to avoid caching issues (or test with all caching disabled). Only change to a 301 when you are sure it's working as intended. You will need to clear your browser cache before testing.

6
  • You are correct about all of the typos. The line end comments were for the readers of this thread, they are going to be removed in .htaccess. I will make all url and parameter fixes needed. The underscores need only to be removed from the final foo_bar.pl, but not the directory names with underscores. So, /Fandom/Fictional_family_trees/Avengers_family_trees.pl needs to be /Fandom/Fictional_family_trees/index.pl?page=Avengers+family+trees. The underscores in Fictional_family_trees do not get converted. – Lady Aleena Jun 22 '20 at 10:27
  • 1
    "The underscores need only to be removed from the final foo_bar.pl" - Yes, that's what the above directives do, the ([\w/]+/) part captures the URL-path upto (but not including) the final path segment. (It's made optional simply because you have a URL in the document root, ie. /about.pl.) – MrWhite Jun 22 '20 at 15:55
  • 1
    "I am willing to accept a better practice" - Well, there's really only "a few" redirects, so it doesn't really matter. And these reduce to just a few directives in .htaccess. The above 10 directives would seem to handle all cases in your redirects above - as far as I can tell. "I wanted these in .htaccess for those who may be coming from a Google search" - it doesn't matter where you implement the redirect (in ..htaccess or in your Perl script) - Google will still see the redirect. – MrWhite Jun 22 '20 at 15:59
  • 1
    I've updated my answer. I had missed the apostrophe (') in 4 of your redirects (eg. .../The_Sisters'_Dilemma.pl) - this has been added to the regex in the above directives. – MrWhite Jun 22 '20 at 16:02
  • 1
    I've also added some notes about using a custom 404 ErrorDocument, although that is really just background information - you don't need to use that method here. – MrWhite Jun 22 '20 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.