301 Redirect Online Logo

Htaccess Redirect Generator (Rewriterule)

    Welcome to the advanced .htaccess mod_rewrite rewriterule code generator. Page to page permanent(moved permanently), temporary(found) redirect and internal rewrite can be generated with the help of mod rewrite engine htaccess code. Copy and paste two columns with old and new urls (for example, from Google Sheets or Excel) into the first field of the online generator. Select options and push "Generate" button. Htaccess rewrite generator will create redirect code you need to insert into your .htaccess file.

Paste lines with Old and New urls here:

Copy Apache .htaccess rewrite rules from here:

Separator between old and new url:

Case sensitiveness:

Reproduce query strings from redirected urls:

Query strings match policy:

How to use online Apache htaccess rewrite generator

Url preparation for mod rewrite htaccess generator

Write down your old and new urls in some table like Google sheets. Use only correct urls with "http" or "https" or just relevant without domain name.

URLs preparation for htaccess redirect generator

Mark, copy and paste both columns into the first field of redirect htaccess generator. Spaces between the urls and line breaks will be inserted automatically.

how to insert urls into mod rewrite generator

Also, you can use any text editor to prepare urls, but be careful with line breaks.

How to choose a separator for urls

Spaces, commas and semicolons can be a part of urls. This tool does not support automatic CSV format recognition and escaping. If You have such a symbol in urls, You will need to choose another separator in your CSV data and htaccess mod rewrite generator options to avoid problems with the generation of rewrite rules.

Tips for htaccess redirect generator

What is the .htaccess redirect?

.htaccess redirect is an Apache configuration file redirect and it is one of the fastest redirects. While redirect rules placed directly in httpd.conf file work faster, .htaccess file can be placed in any directory that is much more convenient especially if no access to server configuration directly. .htaccess file placed in root directory can handle redirects for the whole site. There are two main Apache modules that can produce redirects. The first one is mod rewrite with RewriteCond, RewriteRule rules and the second is mod alias.

Do I need to strip host name on permanent redirect htaccess code generation

By default "delete old host names" option is selected and schema, domain check skipped. If You need a more flexible solution for further usage on other hosts, staging or testing environments, there is an option to strip new host name also. But, if you need to be sure that rules be applied exactly, with conditions on certain hosts, better not to strip. 

How to handle query strings on redirect (htaccess redirect url containing string)

The most common situation is when You replacing urls containing query strings with urls without query strings. This is why the default action with query strings is to skip ones. Also possible to add query string to new url or to combine old and new query strings.  You will need to select the appropriate htaccess rewrite rule generator option.

What does "Query strings match policy" mean?

Let us consider an example: /old_url?str1=val1&str2=val2 .
If to choose "Exact match", urls with exactly the same query string will be redirected.
If to choose "Exact set", only /old_url?str1=val1&str2=val2 and /old_url?str2=val2&str1=val1 will be redirected.
If to choose "Contain", any of the urls like /old_url?str1=val1&str2=val2&str3=val3, /old_url?str2=val2&str1=val1&str5=val5 will be redirected.

The reason for not to escape new urls on redirection

In rare cases, if your valid new url contains special chars like "#"(%23), you may need to choose an option "Do not escape new urls" in order to obtain good results after redirect.

Order of rewrite rules in htaccess redirect code

     The order of the rewrite rules is important. Check Your .htaccess file for redirect rules. Be sure that more narrow rewrite rules are before wider ones. So, if You have htaccess mod rewrite redirect for a whole directory, You need to ensure that your page to page rules are before one. Be careful with htaccess "Redirect 301" or "Redirect permanent" rules. They work on a directory basis and work independently from RewriteRule.

How to insert the code into .htaccess file

First of all, do not insert the code inside common code block generated by WordPress, Joomla, or other CMS, because this way the code can be overwritten after CMS update. Place the code at the begging of the file or where other already working redirects located.

Why not use "Redirect 301" directives

"Redirect 301" or "Redirect permanent" are directives of mod Alias, while this mod rewrite generator uses RewriteCond, RewriteRule. There are a lot of reasons for not to use "Redirect 301". It can't do checks and operations with query strings. It can't check domain names. It will redirect whole directories, but not individual urls. Finally, It has a separate flow. If you have a lot of mod_alias Redirect or RedirectMatch rules, please, use mod Alias page to page RedirectMatch generator or rebuild your old rules with mod rewrite.

I need more, not just page to page redirection. Where can I find more directions?

You can contact us directly or You can use Apache documentation. More about mod_rewrite here.