{"id":7425,"date":"2026-03-27T09:09:14","date_gmt":"2026-03-27T08:09:14","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=7425"},"modified":"2026-03-27T09:09:16","modified_gmt":"2026-03-27T08:09:16","slug":"using-the-mod_rewrite-module","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/","title":{"rendered":"Using the mod_rewrite module"},"content":{"rendered":"\n<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\"><strong>mod_rewrite<\/strong> is a powerful web server module that allows you to modify incoming URL requests on the fly. It is primarily used to create &#8220;clean&#8221; URLs, redirect old pages to new ones, and improve website security by masking the underlying file structure.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Context\" >Context<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Why_use_mod_rewrite\" >Why use mod_rewrite?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#How_it_works_Basic_Rules\" >How it works: Basic Rules<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Advanced_Rewriting_Regular_Expressions\" >Advanced Rewriting (Regular Expressions)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Distinction_Internal_Rewrite_vs_External_Redirect\" >Distinction: Internal Rewrite vs. External Redirect<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Practical_Implications\" >Practical Implications<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/using-the-mod_rewrite-module\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Context\"><\/span>Context<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When a visitor enters a URL, the server usually looks for a specific file (e.g., <code>sklep.php<\/code>). With mod_rewrite, the server can &#8220;intercept&#8221; that request and show content from a different path without the user\u2014or search engines\u2014seeing the complex original address. This process is managed via the <code>.htaccess<\/code> file in your website&#8217;s directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_use_mod_rewrite\"><\/span>Why use mod_rewrite?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<\/div>\n\n<div id=\"mybox-2185161791\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Early access<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Still need help?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contact our customer service team.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Message us<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">Standard dynamic URLs often look like this: <code>http:\/\/www.mycompany.com\/shop.php?category=hats&amp;id=123<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By applying rewrite rules, you can transform them into: <code>http:\/\/www.mycompany.com\/products\/hats\/123\/<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key benefits include:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Search Engine Optimization (SEO):<\/strong> Static-looking links are more easily indexed by search engines.<\/li>\n\n\n\n<li><strong>User Experience:<\/strong> Clean links are easier to remember, read, and share.<\/li>\n\n\n\n<li><strong>Security:<\/strong> Masking script names and variable parameters hides the technical structure of your site from potential attackers.<\/li>\n\n\n\n<li><strong>Stability:<\/strong> If you change your site&#8217;s backend technology, you can keep the same URL structure, preventing broken links.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_it_works_Basic_Rules\"><\/span>How it works: Basic Rules<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To use mod_rewrite, you must include the directive <code>RewriteEngine on<\/code> at the top of your <code>.htaccess<\/code> file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Simple Internal Redirect<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you renamed <code>page.html<\/code> to <code>new_page.html<\/code>, you can ensure the old link still works:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteRule ^page\\.html$ new_page.html\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>^<\/code> marks the start of the path.<\/li>\n\n\n\n<li>The <code>$<\/code> marks the end of the path.<\/li>\n\n\n\n<li>The <code>\\<\/code> before the dot tells the server to treat the dot as a literal character, not a special command.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Forcing a Visible Redirect <code>[R]<\/code><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you want the user&#8217;s browser address bar to actually update to the new URL, add the <code>[R]<\/code> flag:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteRule ^page\\.html$ new_page.html &#91;R]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Advanced_Rewriting_Regular_Expressions\"><\/span>Advanced Rewriting (Regular Expressions)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can use &#8220;wildcards&#8221; to handle multiple addresses at once. This is common for product catalogs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example: Capturing IDs<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteRule ^products\/(&#91;0-9]+)\/$ \/info.php?ID=$1\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>([0-9]+)<\/code>: Matches any sequence of numbers.<\/li>\n\n\n\n<li><code>$1<\/code>: Takes the number found in the first set of parentheses and plugs it into the real URL.<\/li>\n\n\n\n<li>Result: A request for <code>\/products\/123\/<\/code> internally loads <code>\/info.php?ID=123<\/code>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Distinction_Internal_Rewrite_vs_External_Redirect\"><\/span>Distinction: Internal Rewrite vs. External Redirect<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Internal Rewrite:<\/strong> The server shows the new content, but the user\u2019s browser address stays the same. It is a &#8220;transparent&#8221; change.<\/li>\n\n\n\n<li><strong>External Redirect <code>[R]<\/code>:<\/strong> The server tells the browser to go to a new address. The URL in the address bar changes. This is better for moving content permanently.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Practical_Implications\"><\/span>Practical Implications<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Order Matters:<\/strong> Rules in the <code>.htaccess<\/code> file are processed from top to bottom. Place specific rules (like individual page moves) before general rules (like category-wide rewrites).<\/li>\n\n\n\n<li><strong>Syntax Sensitivity:<\/strong> Small typos in an <code>.htaccess<\/code> file can result in a <strong>500 Internal Server Error<\/strong>. Always keep a backup of your working file before making changes.<\/li>\n\n\n\n<li><strong>Trailing Slashes:<\/strong> Be consistent with your use of slashes. A rule for <code>products\/12\/<\/code> will not catch <code>products\/12<\/code> unless you specifically add a rule to handle both.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The mod_rewrite module is an essential tool for maintaining professional, SEO-friendly, and secure URL structures. By mastering a few basic rules and regular expressions, you can ensure your website&#8217;s navigation remains logical and permanent regardless of technical changes.<\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[25],"manual_kb_tag":[],"class_list":["post-7425","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-hosting"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7425\/revisions"}],"predecessor-version":[{"id":7426,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7425\/revisions\/7426"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/media?parent=7425"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manualknowledgebasecat?post=7425"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb_tag?post=7425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}