I'm struggling to correct the aftereffects a bogus redirect I made which led to a lot of 404s. I need to 301 redirect URLs that look like




the example.com/xy and example.com/xy/ parts are permanent, while sometext is unique for each page (i.e. .*)

I'm only starting to undestand mod-rewrite syntax, help much appreciated. Thanks.


ok I figured it out

RewriteRule ^xy(.*)$ /xy/$1 [R=301,L]


Try this:

RewriteCond %{REQUEST_URI} !^/xy/ [NC]
RewriteCond %{REQUEST_URI} ^/xy(.*)$ [NC]
RewriteRule .* http://www.example.org/xy/%1.html [R=301,L]

I think should do it. Please let me know and I can update the answer.

  • I hope you don't mind but I just added the 301 to the redirect statement otherwise the redirect wouldn't have been permanent. – zigojacko Aug 22 '14 at 16:32
  • 1
    @zigojacko Oddly, my personal example(s) had/have the 301 and I removed it because I always thought that R by default was a 301. The edit you made is safer and perhaps I should have left it. Good idea! Thanks. – closetnoc Aug 22 '14 at 16:36
  • hi, thanks. unfortunately it just redirects everything to /xy without adding sometext or even checking if it's xy (i.e. /nzsometext also redirects to /xy – Easy Life Aug 22 '14 at 16:36
  • @Easy Life Back to the drawing board! I will be experimenting with the regex and redirect and should return in a bit. – closetnoc Aug 22 '14 at 16:39
  • just to make it clear - i basically want to add a / i.e. .com/xysometext becomes .com/xy/sometext – Easy Life Aug 22 '14 at 16:42

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.