wrestling with some rewrites for Apache

by Evert   Last Updated July 12, 2018 00:04 AM

I have upgraded my gallery2 to gallery3, and notice that some links no longer resolve correctly. Since the proper way is to redirect these with a 301, that is the way I'm going. The following series need redirecting:


  • old: /v/various/Gry/
  • new: /various/Gry/


  • old: /v/Jacob/02112008310.jpg.html
  • new: /Jacob/02112008310

(both are of course just examples. there are 100's of folders & files to redirect...)

I think there were/are also direct links to images, but those I'm not bothering with for now.

NB. these are the existing rewrite rules:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^$ index.php?kohana_uri=$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]

Where should I insert your lines?

Answers 1

try these... I've made some examples like you mention and these worked. Let me know if you got some corner cases that these rules don't cover.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^v/(.*[^/])/(.*[^/])/ /$1/$2/ [R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^v/(.*[^/])/(.*[^/.])\.(.*).html$ /$1/$2? [R=301]
Hrvoje Špoljar
Hrvoje Špoljar
February 21, 2011 20:36 PM

Related Questions

Problems with apache rewrite

Updated March 26, 2015 07:23 AM

mod_rewrite cause errors in apache error.log

Updated April 17, 2015 00:01 AM