Space Cat, Prince Among Thieves

Batch RewriteRule Generator

Find this useful?Buy me a beer!

- OR -
Donate Bitcoins

Update Dec 2016: Corrected a problem with failing to quote some special characters including hyphen (-).

Update Nov 2016: Added clearer error messages to help with common input errors, as well as support for fully qualified → relative URIs

I find myself often needing to set up a large number of 301 redirects from an excel file of old to new url’s. Until this point, writing these had been a fairly exhausting process as you need to be certain to escape every character that could be picked up by the regular expression engine, or risk unintended consequences. On top of that, writing these rewrites to catch GET parameters in any order is complex to say the least. While working through a large list of 301s for a very picky server where Redirect 301 style redirects were not an option, I began setting up RewriteRule's by hand and decided there had to be a better way. Voila! My 301 RewritRule Builder was born.

Excel Usage Example

You can simply enter a list of tab or space delimited urls (copied from Excel works great) and it will spit out the generated RewriteRule’s for you. GET parameters on the old urls are broken up and built into multiple RewriteCond’s set up to work in any passed order.

I hope someone finds this useful. Any comments are welcome below, of feel free to fork me on github!

Please make sure you have RewriteEngine On somewhere near the top of your .htaccess, before you attempt any rewrites.

Need more help? The tool can only do so much, and sometimes you need human help. I offer .htaccess help as a paid service and have 10+ years of Apache experience. Send me a note on my contact page and we can discuss your options.

Fork my source on Github!

Comment by: Dan Shields on

Dan Shields GravatarI can't believe no one has commented. This thing is the greatest tool ever. I would have figured someone had created this but when searching not much was showing up and you just saved me hours of converting 6 hundred or so urls.

Thanks so much!!

Comment by: Chandra on

Chandra GravatarHey Buddy, I have no words to express.. This is a great tool and you saved my time a lot .. thank you soooooooo much. God this is a wonderful tool :-)

Comment by: Night Lion on

LIFE SAVER. Thanks!

Comment by: Martin Emmert on

Thanks! You saved me a lot of trouble and pain!!

Comment by: Mike on

Mike GravatarThis is just wonderful. Saved me a bunch of mind-numbing data entry. Such a useful tool. THANK YOU!

Comment by: corey on

This tool is the sex

Comment by: eg on

Thanks! You're a life saver!

Comment by: Gareth on

Saved me a huge amount of time and confusion. Many thanks.

Comment by: Anton Evers on

Anton Evers GravatarNice, I'll be using this one more often. I'll fork it too. See if I can tweak the order of the rules so general rules come after specific ones.

Comment by: Anton Sombetzki on

Anton Sombetzki GravatarThanks, first tool I could find that actually works with get parameters! Really nice, bookmarked!

Comment by: Foxman on

Brilliant :) It actually works!!!!! thanks and well done!

Comment by: aseran on

aseran GravatarI agree with you all guys this tool is truely life saver...

Comment by: Anne-Mieke Bovelett on

Anne-Mieke Bovelett GravatarWhere's your PayPal donation button??? This is GREAT stuff!

Comment by: Marc Heatley on

Thanks for this amazing tool! It's a total lifesaver.

Comment by: Alex on

Alex GravatarReally you need a donate button. You don't understand how much this helped me. Thank you so much for making my life so much easier!

Comment by: danna on

danna GravatarThis is great... and over 2 years later even. Thanks so much!

Comment by: Duane on

Thanks so much for such an incredibly great tool!

Comment by: Sagan on

Sagan GravatarThis tool just made my life incredibly easy. We had to create 500 redirects for the relaunch of an ecommerce platform, and this made it incredibly easy. Thank you for making this tool!

Comment by: Eric on

Eric GravatarThe perfect tool I've been searching for 3 hours! Thanks a lot I bought you a beer ;-)

Comment by: Nathan Gaw on

Nathan Gaw GravatarA very useful tool - thanks for putting it together. I bought you a beer. cheers.

Comment by: Raymond on

VERY useful online tool! Thanks for this.

Comment by: Don on

Don GravatarThank you, for this tool. Confirmed. Working like a charm.

Comment by: Eamonn on

Eamonn GravatarGreat work, if only I had found this a a few years back it would have saved a few sleepless nights. Well done!

Comment by: Given on

Given GravatarI salute you. This is awesome :)

Comment by: Vickie on

Vickie GravatarMan, you totally rock! I was just about to give up. Enjoy the beer :D

Comment by: kalyan on

kalyan GravatarHelped me a lot . Good job guys

Comment by: charles on

charles Gravatarawesome tool. thank you so much!

Comment by: Olli on

Olli GravatarThis tool is absolutly awesome and error free. All the best :-)

Comment by: Shaun on

Shaun GravatarAwesome. Thanks. Was stocked when I came across this. Thanks!

Comment by: Koen on

Great tool! Thanks it helps me much

Comment by: David on

David GravatarOMG. Thank you. No kidding, I spent over 10 hours today and yesterday trying to decipher Rewrites for some very complicated URLs. This solved it immediately. This is truly an invaluable tool.

I love that it does bulk processing, but I'm way more impressed with the fact it can decipher irregular characters. It's exceptional!

BRAVO!

Please contact me, and I'll send you a free graphic t-shirt from GAFY.com!

Comment by: Matt on

Matt GravatarYou are a CHAMPION for creating this. Thank you SO. MUCH. I will gladly buy you beer. Buy this man beer, people!

Comment by: mabin on

Awesome tool

Comment by: Andy on

Andy GravatarHi, great tool but if you have hundreds of redirected urls what do you do with the home page re-direct?
Does it go at the bottom of the file? top? and how does it work so the rest of the urls are not skipped please?
Cannot find any info for this when using a htaccess methodnad need to find a working method fast as website now transferred to brand new domain.

Comment by: Jesse G. Donat on

Jesse G. Donat Gravatar

The order actually shouldn't matter at all when using rewrites this creates as it strictly matches.

Entering the following for redirect

http://foo.com  http://bar.com

Returns the following.

RewriteCond %{HTTP_HOST} ^foo\.com$
RewriteRule ^$ http://bar.com/? [L,R=301]

The ^$ means [start][finish] and indicates that this only strictly matches empty so it won't bleed into other matches.

As such you will also want one for index.html/index.php/whatever the real url for your homepage is.


Comment by: David on

David GravatarAll your base are belong to us because this tool is the ish.

I've saved a lot of time! Thanks for the hard work.

Comment by: Hetal Shah on

Hetal Shah GravatarThanks a ton Donat Studios for this excellent tool of rewrite generator. I had been struggling for two days for getting my .htaccess codes right, but this tool solved my problem instantly. Thanks once again !!

Comment by: helen on

helen GravatarThank you, a very useful tool.

Comment by: Michael van Bevern on

Michael van Bevern GravatarTHANK YOU SO MUCH! You solved my day!

Comment by: Lance on

Lance GravatarThis tool is so cool!

Comment by: Luke on

Luke GravatarDude, this tool is so sweet. I'm glad to see you still maintain it. As thanks I bought you a beer last time and I highly encourage others to buy you one too.

Comment by: Philippe on

Philippe GravatarGreat !! Thanks a lot. The htaccess rules are perfectly applied. This 301 generator is the best that I had discovered... until now.

Comment by: Samantha on

Samantha GravatarThank you so much. I have had to do a large number of these on several occasions now. This has saved me sooooooooo much time. Great tool! Thanks again.

Comment by: saravanan on

saravanan GravatarI need to have this work for all of my pages. Please let me know how to do it.Below is my code that works for single page

RewriteCond %{QUERY_STRING} (^|&)where=Oakland%2C\+CA($|&)
RewriteCond %{QUERY_STRING} (^|&)keyword=Beauticians($|&)
RewriteRule ^results\.php$ /results.php/k/Beauticians/Oakland/CA? [L,R=301]

Comment by: jon on

jon Gravatarwell done man, thanks so much, there is nothing else like this out there!

Comment by: Helias on

Helias GravatarI can make it work . I put the generated code into .access and in vhosts.conf file under but server doesnt seem to care. any ideas? p.s I restarted apache services too and in cong file mod_rewrite is enabled and uncommented . apache v 2.2

Comment by: Helias on

Helias GravatarOk the generated code works great, my problem was that i had to add parameters for allowing overrides in vhosts.conf for my vserver. Great tool !!!

Comment by: kamal on

kamal Gravatarlove your tool, it is useable in real sense.

Comment by: Ashok Maharjan on

Thanks, this is an awesome tool. Really save my day. :)

Comment by: Ivan on

Ivan GravatarHi, i´m trying to redirect two kinds of urls but any of them works.

Examples:
1: www.asdasd.com/anuncios/buscar/1/?cat=190&buscar_anuncio=Buscar www.asdasd.com/inmuebles/
2: www.asdasd.com/anuncios/buscar/1/54/ www.asdasd.com/gibraltar/

Number 2 works with redirect 301 /anuncios/buscar/1/54 asdads.es@/gibraltar

Does anyone can help me?

Thanks for help :)

Comment by: Jesse G. Donat on

Jesse G. Donat GravatarHave you tried adding http://? The links will be processed a little differently when it realizes these are full url's and not relative paths.

Comment by: Ivan on

Ivan GravatarYeah i tried, all the urls have the http protocol, but i can´t copy the exact url cause the comments doesn´t accept urls.

Comment by: Simone on

Simone GravatarI love this ... thank you

Comment by: Jaime on

Jaime GravatarHi Jesse, thanks for this great tool!!

Do you know if it´s possible to make some kind of redirection specifying not only the path but also the domain of the old urls?

I need it because I am moving from a Joomla multi-domain website to a Wordpress multi-domain website and I have some identical paths in the old website like these:

www.doamin.com/news.html
www.domain.fr/news.html

So a simple redirect like below always send me to the .com (even in the french scenario) which is the main domain in the multi-domain hosting:

Redirect 301 /news.html http://www.domain.com/category/news/
Redirect 301 /news.html http://www.domain.fr/category/nouvelles/

At this moment the old site is at the ftp root and the new one is in a production subfolder but I have to delete the oldsite and move the new one to the root.. I would need to have the htaccess managing the redirections of all the pages from the oldsite to the new one. I have no problems with the old urls with different paths but, what can I do with the urls with the same path?

I only have one htaccess, since both domains are mangaged from a single CMS installation. (Old joomla site managed the domains with Joomfish plugin and the new wp site manage the domains with WPML).

Thank you!!

Comment by: David on

David GravatarUtterly brilliant. Thanks! Saved me a lot of time doing it by hand.

Comment by: Tom on

GREAT!!! Thank you!

Comment by: Juliette on

This is awesome! Thanks for this.

Comment by: Colin on

This tool is the dogs! thanks for creating :)

Comment by: Greg on

Greg GravatarThis is so great! Thanks so much! You just saved me a bazillion hours of manual coding!

Comment by: Curtis on

Curtis GravatarBrilliant! Hats off to you, sir!

Comment by: Alex on

Alex GravatarThank you very much!!!

Comment by: Guus on

Awesome! Thanks a lot for this wonderful tool!

Comment by: Lorri on

Lorri Gravatarlifesaver! was using the cpanel redirect which broke old cs-cart shopping cart urls (index.php?target=categories&category_id=171) - went through a few rules & tried, then decided there has got to be a generator - went through a few generators - yours is the ONLY one that worked!

Comment by: Scott on

Scott GravatarI can't even begin to explain how much time you just saved me. THANK YOU!!

Comment by: Alex on

Alex GravatarBeautiful tool! Literally shaves hours off large redirect jobs.

Comment by: Jelmer on

Thanks for this !!! Bookmarked for life :)

Comment by: Dave Reeder on

Dave Reeder GravatarThanks, great tool!
This is the only tool that came up with a working redirect for some 404s I had.

Comment by: Evert on

Evert GravatarCool, amazing tool.
I love those simplicity tools that are doing what there are designed for.

Comment by: David on

David GravatarReally good job. Works like a charm.

Comment by: Umal on

Umal GravatarThis is a great tool. Idea is so awesome. Works like charm. Do you have something which can be used to read the existing redirects conf file and update the rewrite rules already present.

Comment by: Kevin on

Kevin GravatarAMAZING! Thank you so much!

Comment by: Hans Wassink on

Thanks Jesse! You are a true G. :) Lifesaver...

Comment by: kikos on

kikos GravatarI have a form with a google map lieke that
http://www.immofind24.de/index.php?controller=pjListings&action=pjActionMap
and i want
http://www.immofind24.de/immobilien-karte.html ..The rewrite is working but the form doesent show anything ..and a field ist already selected with a value ...any ideas ?

Comment by: Russ on

Russ GravatarGreat tool! Thanks. Quick question. I have thousands of old forum links, like this: http://www.fairmontschools.com/Default.aspx?PageID=6849060&A=WebApp&CCID=15683&Page=2&Items=6. They all follow the same pattern, to a point. All of them have http://www.fairmontschools.com/Default.aspx?PageID= and then everything after the equals sign changes. Is there a way to write line in the htaccess file that basically says "anything that has the pattern of http://www.fairmontschools.com/Default.aspx?PageID= should 301 redirect to http://www.fairmontschools.com" ?

Comment by: Roger F. on

Roger F. GravatarGreat tool and real time saver! Was worth for a donation...

Comment by: zonko on

awesome - thanks for this lifesaver

Comment by: bobyfromuk on

bobyfromuk GravatarBest generator of all time! All he is doing!

Comment by: novasta on

novasta Gravatarvery usefull, thank you.

Comment by: Dan Judge on

Great tool, thanks for this.

Comment by: Joe on

Joe GravatarThis is simply amazing. I have been running into query string 301's a lot lately and this is the first usable tool, and arguably the best.

How could one modify it slightly to do the following?

I would want to remove the http host condition as I set the first redirect to push the www to non www version of the site. That condition is already met when I get to my 301's so I don't include it anymore on the individual ones.

Second, how can the output be set the RewriteRule starts with ^(.*)$ instead of the previous html page? in many cases any html page can generate the url so this accounts for all of them?

Again, simply amazing... even without my anal retentive tweaks.

Comment by: Muyassir on

Muyassir GravatarThank you!
It really helped and saved time.

Comment by: James on

James GravatarTHANK YOU. You are awesome!

Comment by: Paul on

Paul GravatarSimply wonderful! You took a mind-numbing task and turned it into a quick and painless process. Thank you!

Comment by: Mohsin Khan on

Mohsin Khan GravatarKilling tool Dudes. Totally flat. Rewrite 5,000 URL's in couple of seconds.... Awesome. Thank-You.

Comment by: Ashley on

Ashley GravatarFantastic! "It just works!" And to anticipate I'd be using Excel for input was all the better. I used it, tested it, then looked for the donation link to contribute. THANK YOU!

Comment by: Marshall on

Marshall GravatarOh. My. Gawd.

This is so incredibly awesome that it goes right past being incredibly awesome, goes all the way around, and comes back to being incredibly awesome.

And you. You're equally incredibly awesome for making it.

Wow.

Comment by: Dmitry on

Excellent work. You are cool guy. Thanks for this tool :)

Comment by: Sherissa on

Sherissa GravatarAwesome tool! thank you.

Comment by: dutch guy on

dutch guy GravatarYessss, this is the supa dupa UBERtool when it comes to creating 301 batchfiles!
Great one, cheers!

Comment by: R34nimated on

Quality tool, saved me about an hour today. Thanks a bunch.

Comment by: David @ eltallerdelbit on

David @ eltallerdelbit GravatarHey! really useful tool!
Like to use it to make my redirections and rewrites ;-)

Thanks!

Comment by: Lamari Abderrahim on

Lamari Abderrahim GravatarGreat work, thank you so much.

Comment by: cataman on

Good Job! thanks bro...

Comment by: Alonzo on

Alonzo GravatarPerfect! I was having a headache, but this solved it! Thanks!

Comment by: andre on

andre GravatarPerfect, thank you for this tool !

Comment by: Amy on

Amy GravatarLet me add a "me, too" for this amazing tool--200+ redirects accomplished in 30 seconds. This is the best.

Comment by: Mariel on

Mariel GravatarThis tool can be used with cms word press friendly url.?
If I can enter a friendly url and it create the correct 301 redirect.?

Comment by: Shervin on

Shervin GravatarGreat tool man, You deserve donation for your great work :)

Comment by: damian on

damian GravatarIt's good. I'd recommend adding some options, such as with/without www and with/without closing "/" at the end of a link. Of course, user would have to be more aware of what they're pasting.

Comment by: Angela Tucker on

Angela Tucker GravatarWow!! Thanks so much on this great time saving tool!! Much appreciated!!

Comment by: Adrian on

Adrian GravatarThank you dearly! I tried a bunch of other generators but none were as good and accurate as this. Thanks a lot.

Comment by: Atur on

Atur GravatarTHANK YOU !!!!!!!!!!!

Comment by: cxvxcvxcv on

THX

Comment by: farzad khaledi on

farzad khaledi GravatarThank you for your great tools,it's work very good :)

Comment by: Alex on

Alex GravatarHi! I generate

# 301 --- /shop/dekorativnye-plenki/category/32-karbon?route=product/category&path=25_32 => /dekorativnye-plenki/karbon
RewriteCond %{QUERY_STRING} (^|&)route=product/category($|&)
RewriteCond %{QUERY_STRING} (^|&)path=25_32($|&)
RewriteRule ^shop/dekorativnye-plenki/category/32-karbon$ /dekorativnye-plenki/karbon? [L,R=301]

But as a result my server redirect me non existed page

/shop/dekorativnye-plenki/category/32-karbon?route=product/category&path=25_32

What is wrong?

Comment by: Voogarix Beethon on

Voogarix Beethon GravatarThank you very much dude.

Comment by: Sumesh on

Sumesh GravatarDo we have any script which does the reverse.

.htaccess file with 1000s lines of redirects, need to convert these into a table data

Comment by: Tim on

Tim GravatarThe rewrites didn't work for me, but the 301s did.

Comment by: karpel on

karpel GravatarExample:
http://www.site.ru/index.php/images/images/file/images/images/index.php	/test/
return not correct.

Comment by: Jesse G Donat on

Jesse G Donat GravatarIt’s doing exactly what you told it to, which computers are one to do. I believe what you meant was:
http://www.site.ru/index.php/images/images/file/images/images/index.php	http://www.site.ru/test/
Update: As this is a common source of error for people I've updated it to better handle FULL→Relative URIs.

Comment by: Naquan on

Naquan GravatarIt WORKS!!!! Thank you!

Comment by: Obat Herbal yang Aman on

Obat Herbal yang Aman Gravatari aprecation help me

Comment by: Alex on

Alex GravatarAmazing tool - love the rewrites - was able to use it for special characters, such as query strings, which you can't do with redirectmatch 301

Lifesaver!

Comment by: Marco on

All you deserve is love. Thanks mate.

Comment by: Ben on

Ben GravatarAwesome tool - thank you for this it's saved tons of time

Comment by: Matt on

Matt GravatarJust the best there is!!

Comment by: Justin on

Justin GravatarHello,

Will this work for http > https ?

example...

http://domain.com/cart/ to https://domain.com/cart/ ?

Comment by: César on

Thanks a lot!

Comment by: Manish on

Manish GravatarThis fails if I have a space or a "%20" in my old url. Any ideas?

Comment by: Manish on

Manish GravatarIf you have a space in the old URL, replace it with "\ " in the htaccess file.

EX: http://domain.com/sub directory/
http://domain.com/sub\ directory/

Comment by: Julian on

Julian GravatarThis tool makes me cry happy.
THANK YOU!

Comment by: Reno on

Reno GravatarHello thanks for this great tool! Was wondering if it can be used for Nginx server too?

Comment by: Christian on

Christian Gravatar%^&*ing great tool > 400 redirects within a wink!

Let the comments on to make debug easier later!

THANK YOU!

Comment by: Brian on

Brian GravatarMany thanks for making this great tool available.

Much appreciated.

Brian

Comment by: Alpakka on

Alpakka GravatarReno: this can be used for nginx configurations, if u combine this with a .htaccess -> nginx converter, such as https://winginx.com/en/htaccess

You need basic understanding on nginx blocks (to avoid duplicates etc with your existing configurations), but I quess you have that if ur working with nginx.

Just did around 100 Rewrites combining these 2 tools. Amazing.

Comment by: Jorge on

Jorge GravatarHello,

I'm trying to get rewrite but don't work for me. Can you help me. Now I have 6000 Redirec 301 and I would like to convert into rewriterules.

Comment by: Alex on

Alex GravatarI donated again. I've used this tool many times. I can't thank you enough for this.

Comment by: itzik glam on

amazing
thank you

Comment by: Imran on

Imran GravatarHi,

I'm about to use this to redirect 9000 .asp pages to static HTML links which are all Magento pho.

Will this work with asp pages as the old page:

E.g.

Www.oldpage.com/store/product.asp=1234

To

Www.newpage.com/bed.html

Comment by: Hamish Lowry-Martin on

Just sent ya a beer, thanks for the tool

Comment by: Dmitriy on

thanks for the tool

Comment by: Andrew Lee on

You're awesome

Comment by: Lesscro on

Lesscro Gravatarmade a small donation because u help me everyday in my work... Really a piece of work when needed !!!

Comment by: Patrick Büttgen on

Patrick Büttgen GravatarNice Tool, thank you!

Comment by: Pro Bg on

Great tool.

Comment by: Bessonweb on

Very helpful ! Thanks for the tool :-)

Comment by: Bob on

Bob GravatarYears after still rocks! Thank you!

Comment by: Jessica on

Jessica GravatarJust saved the night. I can go to bed now. Thank you!

Comment by: Looke on

Looke GravatarGod this is awesome! good job!

Comment by: hieu on

hieu GravatarHi, sorry for bother you. I dont know how to use it

Comment by: Some dude on

Some dude GravatarHow do I force lowercase on new URL? For example, OLD URL uses a mix of upper and lower case characters, but only want lowercase. Can you maybe add checkbox to convert case or share how to change autodirect both uper and lower mix to just lower?

Comment by: Jesse G. Donat on

Jesse G. Donat GravatarPresuming you're wanting to convert mix of any casing to lower case, and not a specific mixed case set, you're going to more htaccess logic than this is built to generate - using regex flags and rewritecond's.

It's out of scope of what this is meant for.

If you were interested, I offer htaccess help as a paid service. You can contact me via my contact page and we can discuss options.

Comment by: Daniel Dewhurst on

Daniel Dewhurst GravatarStill the best htaccess redirect generator.

Comment by: Miki on

Miki GravatarTHIS IS FCKING GREAT! Thanks Mate !!

Email address will never be publicly visible.