Take the 2-minute tour ×

I am porting a site from an old version of a CMS to a newer version which has different page addressing techniques. I'm unfortunately not very good with htaccess at all.

URL/blog/sublblog/article.html is now simply URL/article.html

Unfortunately, this will destroy any linking programs they have going, and break all the old links. I need a way to use .htaccess say:

if request = /(any subdirectory)/(string).html
then redirect to /(string).html

If that makes any sense.

share|improve this question
What have you tried so far? Can you paste the code? Which error do you get? Have you worked through a tutorial? –  Michael Jun 19 '12 at 18:38
I've not tried much, as I don't understand how to do it. I'm not sure what code you'd like me to paste, and this isn't an error situation. I've worked through several tutorials, most of which cover similar information to the one you linked. They're primarily discussing single page redirects and things, not something this complicated. I'm not even sure if it's possible to do what I want to do. –  jeffreylees Jun 19 '12 at 18:52
I mean code like RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301] which is part of the tutorial linked above. If you read something about regular expressions, you should be able to adapt the examples from there. –  Michael Jun 19 '12 at 18:58

2 Answers 2

up vote 1 down vote accepted

Edited because other one failed:

RewriteEngine on
RewriteBase /
RewriteRule ^blog/subblog/(.*)$ http://www.example.com/$1 [R=301,L]

Can you try this and give the results?

share|improve this answer
This works, for a specific entry. Is there any way for it to do this for any string, so that I don't need to create an entry for every article ever published? Or is that just how it's going to be? –  jeffreylees Jun 19 '12 at 19:23
This should work for http://www.example.com/blog/subblog/[anything] going to http://www.example.com/[anything]. If you need to change the folders "blog/subblog" then add the rewrite rule in stacks (Copy and Paste) and change the URLs as needed. If your URLS are by Date, I think you're out of luck, unless you can find a wildcard regex to use for "Two Slashes". –  ionFish Jun 19 '12 at 20:03
I did end up doing basically this, and making a list for every folder and subfolder, as I couldn't find any sort of wildcard expression. Thanks for the help. –  jeffreylees Jul 4 '12 at 12:42

You need to do a 301 redirect.

In your .htaccess file, add a line like this:

redirect 301 URL/blog/sublblog/article.html URL/article.html

You will have to do this for each url that you need to redirect, so you could end up adding a ton of entries.


share|improve this answer
You should read the other answers before posting your own. You will have to do this for each url that you need to redirect, so you could end up adding a ton of entries. << that's not true at all. We use wildcards in that case. Similar question can be adapted: webmasterworld.com/apache/3939066.htm –  ionFish Jun 19 '12 at 20:28
Please read my answer carefully before jumping the gun: if you do it manually like I pointed it out, it could take a lot work to achieve it, which works well for sites with no more than 100 entries, but definitely not a good option for sites that need to redirect lots of urls. –  Marcelo Jun 21 '12 at 2:08
We can both agree that the asker was unclear in the exact format of how many unique directories there were to be routed. My apologies. –  ionFish Jun 21 '12 at 2:19

Your Answer


