{"id":929,"date":"2016-03-21T11:20:36","date_gmt":"2016-03-21T09:20:36","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=929"},"modified":"2018-05-31T15:44:05","modified_gmt":"2018-05-31T12:44:05","slug":"apache-url-rewrite-example","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/","title":{"rendered":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite"},"content":{"rendered":"<p><em>In this post, we feature a comprehensive Apache URL rewrite example. This article is part of our Academy Course titled <a href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-http-server-tutorial\/\">Apache HTTP Server Tutorial<\/a>.<\/em><\/p>\n<p>In this course, we provide a compilation of Apache HTTP Server tutorials that will help you get started with this web server. We cover a wide range of topics, from installing the server and performing a basic configuration, to configuring Virtual Hosts and SSL support. With our straightforward tutorials, you will be able to get your own projects up and running in minimum time. Check it out <a href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-http-server-tutorial\/\">here<\/a>!<\/p>\n<p>In <a href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-mod_rewrite-example\/\" target=\"_blank\" rel=\"noopener\">Apache mod_rewrite example: Redirecting and rewriting URLs<\/a>, we introduced you to Perl Compatible Regular Expressions (PCRE) and explained how to integrate them with the mod_rewrite Apache module. These tools allow us to perform URL rewriting and redirecting for a variety of purposes at our convenience.<\/p>\n<p>In this tutorial we will build on these concepts and share other examples of URL rewriting you should have handy as a system administrator.<\/p>\n<h2>1. Redirecting to a new resource in the same server<\/h2>\n<p>If you have changed the name of a page and want both the old and new URLs to be functional (meaning both lead to the new URL), mod_rewrite allows you to get the job done in a transparent way for end users, who will not notice the difference in their browsers. In this example we will use the example1.com virtual host.<\/p>\n<p>For simplicity, let\u2019s suppose that we had a page named <strong>about.html<\/strong> and we renamed it to <strong>aboutus.html<\/strong>. Since we do not want users to notice the change, all requests to <strong>about.html<\/strong> must be rewritten to <strong>aboutus.html<\/strong>.<br \/>\n[ulp id=&#8217;euI76dOod8fb2P3K&#8217;]<\/p>\n<p>To accomplish this, we need to insert the following line at the end of the virtual host block for example1.com:<\/p>\n<pre class=\"brush:xml\">RewriteRule\u00a0\u00a0\u00a0 \"^\/about\\.html$\" \u00a0\"\/aboutus.html\"\r\n<\/pre>\n<p>After saving changes to the configuration file, restart Apache and browse to <strong>http:\/\/example1.com\/about.html<\/strong> as seen in Fig. 1:<\/p>\n<figure id=\"attachment_932\" aria-describedby=\"caption-attachment-932\" style=\"width: 801px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-932 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/01rw.png\" alt=\"Apache URL rewrite example: 01rw\" width=\"801\" height=\"277\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/01rw.png 801w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/01rw-300x104.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/01rw-768x266.png 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><figcaption id=\"caption-attachment-932\" class=\"wp-caption-text\">Figure 1: Redirecting to a new resource without visible URL change<\/figcaption><\/figure>\n<p>As you can see, there is no page named about.html in the DocumentRoot of example1.com, but the rewrite rule caused Apache to serve aboutus.html instead. In the address bar the end user will not notice the difference. However, if you use replace the previously added rewrite rule with this one<\/p>\n<pre class=\"brush:xml\">RewriteRule\u00a0\u00a0\u00a0 \"^\/about\\.html$\" \u00a0\"aboutus.html\" [R]\r\n<\/pre>\n<p>the URL in the address bar WILL change and the request will be logged accordingly, as we can see in Fig. 2:<\/p>\n<figure id=\"attachment_933\" aria-describedby=\"caption-attachment-933\" style=\"width: 771px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-933 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/02rw.png\" alt=\"Apache URL rewrite example: 02rw\" width=\"771\" height=\"412\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/02rw.png 771w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/02rw-300x160.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/02rw-768x410.png 768w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/02rw-620x330.png 620w\" sizes=\"(max-width: 771px) 100vw, 771px\" \/><figcaption id=\"caption-attachment-933\" class=\"wp-caption-text\">Figure 2: Redirecting to a new resource with visible URL change<\/figcaption><\/figure>\n<p>In this last case, the [R] rewrite flag is used to cause the HTTP redirect to be issued to the browser. The 302 HTTP response indicates that the browser is \u201ctold\u201d to make a second request to the new URL. This behavior can be see in Fig. 2 above.<\/p>\n<h2>2. Redirecting to a resource moved to another server<\/h2>\n<p>If for some reason you need to move a page (or any kind of file, for that matter) to a different server, you will want your users to still be able to access that resource by browsing to the usual URL. This option may come in handy if you need to move a site between servers, or to leverage the available bandwidth of the second system.<\/p>\n<p>For example, let\u2019s say we have a video file named video.mp4 inside the media folder of example1.com, and we want to move it to the DocumentRoot directory of example2.com. Since we are hosting both virtual hosts inside the same machine, we will simply use the <b>mv <\/b>command (in other situations, you will use <b>scp <\/b>or <b>sftp <\/b>to transfer the file) to change the location (see Fig. 3 for details):<\/p>\n<figure id=\"attachment_934\" aria-describedby=\"caption-attachment-934\" style=\"width: 935px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-934 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/03rw.png\" alt=\"Figure 3: Apache URL rewrite example: Moving a video file to a different virtual host\" width=\"935\" height=\"175\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/03rw.png 935w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/03rw-300x56.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/03rw-768x144.png 768w\" sizes=\"(max-width: 935px) 100vw, 935px\" \/><figcaption id=\"caption-attachment-934\" class=\"wp-caption-text\">Figure 3: Moving a video file to a different virtual host<\/figcaption><\/figure>\n<p>To allow users to access video.mp4 when they type <strong>http:\/\/example1.com\/video.mp4<\/strong>, use the following rewrite rule in the virtual host block:<\/p>\n<pre class=\"brush:xml\">RewriteRule \u00a0\u00a0\"^\/video\\.mp4\" \u00a0\"http:\/\/example2.com\/$1\" \u00a0[R,L]\r\n<\/pre>\n<p>Now save changes, don\u2019t forget to restart Apache, and let\u2019s see what happens in Fig. 4:<\/p>\n<figure id=\"attachment_935\" aria-describedby=\"caption-attachment-935\" style=\"width: 970px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-935 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/04rw.png\" alt=\"Apache URL rewrite example: 04rw\" width=\"970\" height=\"412\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/04rw.png 970w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/04rw-300x127.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/04rw-768x326.png 768w\" sizes=\"(max-width: 970px) 100vw, 970px\" \/><figcaption id=\"caption-attachment-935\" class=\"wp-caption-text\">Figure 4: Serving a resource that has been moved to a new server<\/figcaption><\/figure>\n<p>In Fig. 4 we can see that the request to <strong>http:\/\/example1.com\/video.mp4<\/strong> was actually handled by example2.com. The combination of the R and L flags in the rewrite rule tells Apache to 1) perform a redirect, and 2) disregard further rules, respectively.<\/p>\n<h2>3. Serve browser-dependent content<\/h2>\n<p>You can also use mod_rewrite to present a different file as home page based on the end user\u2019s browser. We will use four different files (firefox.html, chrome.html, ie.html, and elinks.html for Mozilla Firefox, Google Chrome, Internet Explorer, and the text-based elinks browsers, respectively) for this. Refer to Fig. 5 for details:<\/p>\n<figure id=\"attachment_937\" aria-describedby=\"caption-attachment-937\" style=\"width: 811px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-937 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/05rw.png\" alt=\"Figure 5: Apache URL rewrite example: Different pages to present depending on the user's browser\" width=\"811\" height=\"391\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/05rw.png 811w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/05rw-300x145.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/05rw-768x370.png 768w\" sizes=\"(max-width: 811px) 100vw, 811px\" \/><figcaption id=\"caption-attachment-937\" class=\"wp-caption-text\">Figure 5: Different pages to present depending on the user&#8217;s browser<\/figcaption><\/figure>\n<p>Add the following lines to the configuration file of example2.com inside the virtual host block. Note that this relies on the <strong>HTTP_USER_AGENT<\/strong> environment variable, which stores the user-agent string identifying the browser:<\/p>\n<pre class=\"brush:xml\">RewriteCond \"%{HTTP_USER_AGENT}\" \u00a0\".*Firefox.*\"\r\nRewriteRule \"^\/foo\\.html$\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/firefox.html\" [L]\r\nRewriteCond \"%{HTTP_USER_AGENT}\" \u00a0\".*ELinks.*\"\r\nRewriteRule \"^\/scg\\.html$\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/elinks.html\" [L]\r\nRewriteCond \"%{HTTP_USER_AGENT}\" \u00a0\".*Chrome.*\"\r\nRewriteRule \"^\/scg\\.html$\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/chrome.html\" [L]\r\nRewriteCond \"%{HTTP_USER_AGENT}\" \u00a0\".*Trident.*\"\r\nRewriteRule \"^\/scg\\.html$\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/ie.html\" [L]\r\nRewriteRule \"^\/scg\\.html$\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"\/index.html\" [L]\r\n<\/pre>\n<p>You will notice that the regular expressions used in the above rewrite rules look for a match inside the user agent string (which can be rather large, such as <b><i>Mozilla\/5.0 (Windows NT 6.1; rv:44.0) Gecko\/20100101 Firefox\/44.0<\/i><\/b>).<\/p>\n<p>Depending on the browser, a different page will be displayed when the user requests <strong>http:\/\/example2.com\/scg.html<\/strong> (note that this file does not exist in the DocumentRoot of this virtual host). If the browser is neither Firefox, Chrome, IE (identified by the string <em>Trident<\/em>) or elinks, the request will be redirected to index.html.<\/p>\n<p>In Fig. 6 we see how Apache has returned different pages for each of the four browsers mentioned earlier. We also used w3m (another text-based browser) to illustrate the default action when the user agent string does not match the rewrite conditions (in this case, the usual index.html page is served):<\/p>\n<figure id=\"attachment_938\" aria-describedby=\"caption-attachment-938\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-938 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/06rw.png\" alt=\"Figure 6: Apache URL rewrite example: Returning different pages depending on the user agent string\" width=\"860\" height=\"366\" srcset=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/06rw.png 860w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/06rw-300x128.png 300w, https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/03\/06rw-768x327.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><figcaption id=\"caption-attachment-938\" class=\"wp-caption-text\">Figure 6: Returning different pages depending on the user agent string<\/figcaption><\/figure>\n<p>Why would you want to use mod_rewrite for this? For example, because some browsers may not be compatible with certain versions of Javascript libraries, or perhaps you want to have a minimal page for text-based browsers.<\/p>\n<h2>Summary<\/h2>\n<p>In this article we have shared a few extra examples of URL rewriting and redirecting with the intent to give you a glimpse of the capabilities of mod_rewrite. Fortunately, the Apache website provides lots of useful information and examples about the use of this module. With that in mind, the sky is the limit!<\/p>\n<p>We hope that you have found this tutorial useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we feature a comprehensive Apache URL rewrite example. This article is part of our Academy Course titled Apache HTTP Server Tutorial. In this course, we provide a compilation of Apache HTTP Server tutorials that will help you get started with this web server. We cover a wide range of topics, from installing &hellip;<\/p>\n","protected":false},"author":15,"featured_media":184,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-929","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/gacanepa\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-21T09:20:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-31T12:44:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gabriel Canepa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gacanepa\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gabriel Canepa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\"},\"author\":{\"name\":\"Gabriel Canepa\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\"},\"headline\":\"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite\",\"datePublished\":\"2016-03-21T09:20:36+00:00\",\"dateModified\":\"2018-05-31T12:44:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\"},\"wordCount\":1133,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"articleSection\":[\"Apache\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\",\"name\":\"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"datePublished\":\"2016-03-21T09:20:36+00:00\",\"dateModified\":\"2018-05-31T12:44:05+00:00\",\"description\":\"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Servers\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Apache\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/apache\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\",\"name\":\"Gabriel Canepa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"caption\":\"Gabriel Canepa\"},\"description\":\"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.\",\"sameAs\":[\"http:\/\/www.gabrielcanepa.com.ar\/\",\"https:\/\/www.facebook.com\/gacanepa\",\"https:\/\/ar.linkedin.com\/in\/gacanepa\",\"https:\/\/x.com\/gacanepa\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026","description":"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/","og_locale":"en_US","og_type":"article","og_title":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026","og_description":"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.","og_url":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_author":"https:\/\/www.facebook.com\/gacanepa","article_published_time":"2016-03-21T09:20:36+00:00","article_modified_time":"2018-05-31T12:44:05+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","type":"image\/jpeg"}],"author":"Gabriel Canepa","twitter_card":"summary_large_image","twitter_creator":"@gacanepa","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Gabriel Canepa","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/"},"author":{"name":"Gabriel Canepa","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f"},"headline":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite","datePublished":"2016-03-21T09:20:36+00:00","dateModified":"2018-05-31T12:44:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/"},"wordCount":1133,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","articleSection":["Apache"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/","url":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/","name":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","datePublished":"2016-03-21T09:20:36+00:00","dateModified":"2018-05-31T12:44:05+00:00","description":"Interested to learn more about Apache url rewrite? Then check out our detailed Apache URL rewrite example where we will build on some fundamental concepts and share other examples of URL rewriting everyone should has in handy as a system administrator.","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/apache-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/apache\/apache-url-rewrite-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Servers","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/"},{"@type":"ListItem","position":3,"name":"Apache","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/apache\/"},{"@type":"ListItem","position":4,"name":"Apache URL rewrite example: Rewriting and redirecting URLs with mod_rewrite"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f","name":"Gabriel Canepa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","caption":"Gabriel Canepa"},"description":"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.","sameAs":["http:\/\/www.gabrielcanepa.com.ar\/","https:\/\/www.facebook.com\/gacanepa","https:\/\/ar.linkedin.com\/in\/gacanepa","https:\/\/x.com\/gacanepa"],"url":"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=929"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/929\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/184"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}