title: Regular Expression and .htaccess: redirect /cat1/cat2/ → /cat2/
body: <p>I'm trying this regex but there are a few problems.. /tag/ shouldn't be stripped /page/2 neither and also  </p>
  
  <pre><code>/.*?(/[^/]+/)([^/]*)(/feed)?$
  </code></pre>
  
  
  
  <pre><code>/.*? → match / followed by anything 
  (/[^/]+/) → match the last category
  ([^/]*) → match the name of the file
  (/feed)? → match the /feed if it's there
  $
  </code></pre>
  
  <p>URLs:</p>
  
  <pre><code>http://www.regexbuddy.com/prova/prova1/index.html
  http://www.regexbuddy.com/index.html?source=library
  https://www.superinformati.com/medicina-e-salute/diete/feed
  https://www.superinformati.com/medicina-e-salute/estetica-cosmesi/calvizie/feed
  https://www.superinformati.com/medicina-e-salute/denti/feed
  https://www.superinformati.com/bellezza/capelli/feed
  https://www.superinformati.com/hi-tech/schermi-amoled-costo-inferiori-agli-lcd.htm/page/20
  https://www.superinformati.com/soldi-successo/consumatori/page/2
  https://www.superinformati.com/medicina-e-salute/disabilita/feed
  https://www.superinformati.com/medicina-e-salute/emorroidi/feed
  https://www.superinformati.com/medicina-e-salute/anticoncezionali
  https://www.superinformati.com/category/bellezza/tatuaggi
  https://www.superinformati.com/bellezza/tatuaggi/feed
  https://www.superinformati.com/category/medicina-e-salute/dimagrire
  https://www.superinformati.com/medicina-e-salute/farmaci-istruzioni/feed
  https://www.superinformati.com/bellezza/cellulite/feed
  https://www.superinformati.com/medicina-e-salute/occhi/feed
  https://www.superinformati.com/bellezza/capelli
  https://www.superinformati.com/medicina-e-salute/estetica-cosmesi/chirurgia-estetica
  https://www.superinformati.com/tag/high-tech/feed
  https://www.superinformati.com/category/medicina-e-salute/maternita
  https://www.superinformati.com/tag/antiossidanti
  https://www.superinformati.com/psicologia/la-polemica-porta-vantaggi.htm
  https://www.superinformati.com/universita/come-scrivere-un-cv-da-inviare-allestero.htm
  https://www.superinformati.com/soldi/consumatori/
  https://www.superinformati.com/bellezza/tatuaggi
  https://www.superinformati.com/medicina-e-salute/estetica-cosmesi
  https://www.superinformati.com/medicina-e-salute/farmaci-istruzioni
  https://www.superinformati.com/medicina-e-salute/occhi
  https://www.superinformati.com/medicina-e-salute/diete
  https://www.superinformati.com/dimagrire/integratori
  </code></pre>