Space Cat, Prince Among Thieves

Batch RewriteRule Generator

Find this useful?Buy me a coffee!

PayPal:

GitHub:

Ko-Fi:

Buy Me a Coffee at ko-fi.com

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 RewriteRule 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: Andy on

Hi, 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

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: Ivan on

Hi, 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

Have 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: Atur on

THANK YOU !!!!!!!!!!!

Comment by: cxvxcvxcv on

THX

Comment by: farzad khaledi on

Thank you for your great tools,it's work very good :)

Comment by: Alex on

Hi! 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

Thank you very much dude.

Comment by: Sumesh on

Do 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

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

Comment by: karpel on

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

Comment by: Jesse G Donat on

It’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

It WORKS!!!! Thank you!

Comment by: Alex on

Amazing 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

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

Comment by: Matt on

Just the best there is!!

Comment by: Justin on

Hello,

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

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

Comment by: Manish on

If 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

This tool makes me cry happy.
THANK YOU!

Comment by: Reno on

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

Comment by: Christian on

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

Let the comments on to make debug easier later!

THANK YOU!

Comment by: Brian on

Many thanks for making this great tool available.

Much appreciated.

Brian

Comment by: Alpakka on

Reno: 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

Hello,

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

I 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

Hi,

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

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

Comment by: Patrick Büttgen on

Nice Tool, thank you!

Comment by: Pro Bg on

Great tool.

Comment by: Bessonweb on

Very helpful ! Thanks for the tool :-)

Comment by: Bob on

Years after still rocks! Thank you!

Comment by: Jessica on

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

Comment by: Looke on

God this is awesome! good job!

Comment by: hieu on

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

Comment by: Some dude on

How 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

Presuming 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

Still the best htaccess redirect generator.

Comment by: Mike on

2018 and still works like a charm!

Comment by: Jef on

excellent work!
this is the only htaccess generator worked on my case!
thanks!

Comment by: Erickson Bolivar on

OMG,You are the best, i love you

Comment by: Sasha on

Respect from Russia! Very usefull script ;)

Comment by: Dave R on

This tool is awesome! This is the only tool that solved my redirect problem.

Comment by: viktor on

Add a special character escaping in the GET parameter, some web servers cannot do without IT
RewriteCond %{QUERY_STRING} (^|&)id\=x($|&)
RewriteRule ^page\.php$ /page.php\?fid=x [L,R=301]
?fid=x -> \?fid=x

Comment by: Jesse G. Donat on

In my experience this is always something misconfigured on your server. It should not be necessary to escape the ?.

Comment by: Phil on

Hey

its possible todo this?

https://subdomain.domain.tld => https://subdomain.domain.tld/subdomainfolder?

Thank u

Comment by: Julien Gray on

Dude, you are a legend. Saved me hours. Bought you a beer!

Comment by: Bruno on

A real help! Thanks!

Comment by: Luís Brito on

A great tool! Thanks mate!

Comment by: Clay Ravin on

This tool is great, thanks making it available!

Comment by: Clay Ravin on

Or even thanks FOR making it available!

Comment by: Igor on

Супер инструмент! Очень помог. Большое спасибо автору от России!!!

Comment by: Dimitri on

Great tool!! small issue:
when redirecting to the same url than this line should be skippet, this should not be possible:

# 301 --- https://testsite.com/contact => https://testsite.com/contact
RewriteRule ^contact$ /contact? [L,R=301]

We get a lot of list with somtimes redirects that do no need redirecting. than this check would be good.

Comment by: Michel Remacle on

Thanks mate!

Comment by: Tom on

Good work! Only problem is that there's no option to decode URLs, sometimes it's needed. E.g. I copied these old and new URLs from browser address bar and pasted it in your tool. I got this:

# 301 --- a.php => b.php?filter%5B%5D=somevalue
RewriteRule ^a\.php$ /b.php?filter%5B%5D=somevalue [L,R=301]

The problem is, %5 doesn't make it to the final URL, when Apache rewrites it so this redirect is unusable. It's probably because '%' is a special character, I'm not sure. Flags B and NE don't help. Only thing that helped me was to decode that URL so I got this: b.php?filter[]=somevalue

Btw I created a similar tool http://redirectgenerator.netmagnet.cz/ :)

Comment by: Kevin on

Thank you! Worked great! I needed to do some search and replace afterward. Maybe it would be very easy for you to copy your existing code, paste it, and make another that provides the following result:


RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^colorado\-renters\-rights\-law\.html$ "https\:\/\/domain\.com\/colorado\-renters\-rights\-law\/" [R=301,L]

Thanks again! What a great tool!

Comment by: Ignacio Durán on

esta aplicación es INCREIBLE!!! GRACIAS!

Comment by: Remo on

Great tool! A handy addition in my opinion would be an option to make trailing slashes in the match optional (RewriteRule ^request_uri?/$), besides that it just works perfectly!

Comment by: Sreenivas Reddy on

Great redirection tool... It is working perfectly.

TIME-SAVING TOOL

Thank you

Comment by: Al on

Thank you for providing such a great tool. How can we handle name attribute, #abc below, at the end of a query in a link? It seems they are ignored in this tool.
text/faq.html?faq=20#abc	helpdesk/kb.php

# 301 --- text/faq.html?faq=20#Ben => helpdesk/kb.php
RewriteCond %{QUERY_STRING} (^|&)faq\=20($|&)
RewriteRule ^text/faq\.html$ /helpdesk/kb.php? [L,R=301]
I tried the following and it did not work. RewriteCond %{QUERY_STRING} (^|&)faq\=20\#Ben($|&) Any help would be greatly appreciated.

Comment by: Jesse G Donat on

The "URL fragment" - the part after the # - is not communicated to the web server and thus cannot be used as something to base redirection on.

Comment by: STEPHANE on

wow .. thanks a lot, very useful!!

Comment by: Steve on

This is just brilliant - thanks so much!

Comment by: Wannes on

What a lovely tool!

Comment by: Max on

Thank you so much!
This is the best tool! I found exactly what I was looking for

Comment by: MyGoodJob on

Спасибо тебе, дружище!

Comment by: Michael Rock on

When setting up a redirect through cPanel and it is a WordPress site it forces it to the bottom of the .htaccess files then does not work. By using your tool and manually adding it to the top of the .htaccess file it worked beautifully! Thank you! It took a while of searching to come across a tool where you can input multiple 301 redirects.

Comment by: Mike Lopez on

I have a website https://top5stories.com and i want to redirect all the post there in 1 page. Is that possible?

Comment by: s w on

Awesome tool! i HAVE JUST USED IT WITH NO FAIL!

Comment by: Michael on

You're a lifesaver. Great tool, keep it up!

Comment by: Jason Schaeffer on

Two-hundred-fifty 301s verified you are a great human. Thank you for this amazing tool!!!

Comment by: viktor on

<div class="Comment">Add a special character escaping in the GET parameter, some web servers cannot do without IT
RewriteCond %{QUERY_STRING} (^|&)id\=x($|&)
RewriteRule ^page\.php$ /page.php\?fid=x [L,R=301]
?fid=x -> \?fid=x
</dive>


<code>?</code> - it is necessary to screen since it is a special character, this is certainly not superfluous.
<code>=</code> you are screening although here it never leads to problems, the special symbol is not.
https://httpd.apache.org/docs/2.4/rewrite/intro.html

<code>?</code> on some servers you really have to screen, otherwise the redirect does not work.

According to the current description, this is a special character.

Comment by: kumar on

how to redirect all .php to / in .htaccess

example http://mywebsite.com/abc.php to http://mywebsite.com/abc/

Comment by: Ignacio on

please, put some banners in your web and I will click them all!!! love your page.

Comment by: Victor Ekpo on

THE BEST... you the you the best

Comment by: shambler81 on

please add
before
(^|&).....($|&)
after
(?:^|&).....(?:$|&)
this will not affect the logic in any way, but it will be convenient to count the groups

Comment by: Jesse G Donat on

Thanks for the suggestion - it was a great idea! I always end up doing it myself when writing custom rules, might as well do it off the bat. I've implemented it!

Comment by: Angelo on

Everybody thinks it's a great tool. But I think there's something wrong with it. You write in the description of the tool: "I hope someone finds this useful". That phrase is obsolete, man. Of course your tool is awesome.

You should write instead: "Check this goddamn awesome tool of mine, bro. Any comments are welcome below, ..."

Comment by: Alan on

Simple but effective. Thanks for the tool.

Comment by: Marek on

You're the best! :) Thanks!

Comment by: leandev on

Awesome, it's 2020 and im still using this :)
Definetelly saved me alot of time

Comment by: Tinny on

Thank you!

Comment by: Mar on

Okay, you're AWESOME! seriously, just discovered this in 2021. You my friend, are the real deal.

Comment by: Rick Altman on

I believe this is just what I am now looking for, ever since our ISP changed its site tools and no longer allows sites to redirect to other sites. But I am not clear on what "this" is: is it a technique for editing .htacess, or is it an actual app that I download and use?

I need a tiny bit of hand-holding to get started...

Comment by: Dave Reeder on

Thankyou so much for this, it is an amazing tool, I wouldn't be able to do some redirects without this!
The fact it can do complex urls with query strings etc. it's very impressive.

Comment by: olivia jaacob on

i want to help my website its create a various seo not friendly url, check example ? https://logodesigns.us/ its main domain, create different url https://logodesigns.us/?/mail= this type of url please help me i am waiting ? ? thanks

Comment by: Nikiforov on

Great tool, but I have one question - why the "\" character is inserted in the url? Below you can see example.

This is what I pasted to first field (old-new url):
https://www.domain.lt/old-category/subcategory/product-good-1-2 https://www.domain.lt/new-category/subcategory/product-good-1-2

This is what I get after I push “Submit Query” button:
# 301 --- https://www.domain.lt/old-category/subcategory/product-good-1-2 => https://www.domain.lt/new-category/subcategory/product-good-1-2
RewriteRule ^old\-category/subcategory/product\-good\-1\-2$ /new\-category/subcategory/product\-good\-1\-2? [L,R=301]

In the line „RewriteRule“ I see 8 characters „\“. Why? In my url no free space. You can test with my example and will get the same result. Of course I tried both variants and al lis working perfest, but questions is still. ????

Comment by: Dead support on

Dead support

Comment by: Flo on

What a livesaver tool, thank you very much!!

@Nikiforov the backslash is to mark the special character in the string, it belongs there.

Comment by: Gianluca Zamagni on

Always helpful when in a rush! Thank you ????

Comment by: ZUGEMU on

THANK you for ur contribut....
It help me lot ....

willing to buy beer for you !!!

Comment by: Vandalorian on

Not all heroes wear capes <3

Comment by: textgen.pl on

Yeah! Great tool:)

Comment by: Roland on

Still a valuebable tool. Thanks!

Comment by: Nikolai on

Where should I paste this code? If, for example, I want to redirect from https://ya.ru/ to https://www.google.com/ in all browsers on the computer

Comment by: Jesse G. Donat on

That's not what this is for. This is for redirecting requests into an Apache webserver. If you're looking to redirect local browser requests on your computer, you'll need software designed for that purpose.

Comment by: Gullivan on

the best

Email address will never be publicly visible.

Basic HTML allowed.