{"id":280,"date":"2021-05-04T03:24:09","date_gmt":"2021-05-04T03:24:09","guid":{"rendered":"https:\/\/arzhost.com\/blogs\/?p=280"},"modified":"2023-10-04T14:59:14","modified_gmt":"2023-10-04T14:59:14","slug":"rewrite-rule-index-php","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/","title":{"rendered":"The Rewrite Rule ^index.php$ &#8211; [l]: A Beginner&#8217;s Guide"},"content":{"rendered":"<p>Rewrite Rule proves the request. shape is an ordinary clarification that organizes with the ideal string from the URL, which is what the watcher types in the program. substitution is the way to the real URL, for example the method of the record Apache employees. flags are optional limits that can change how the standard capacities. A Beginner&#8217;s Guide Rewrite Rule ^index.php$ &#8211; [l].<\/p>\n<p>.htaccess consideration rule wires setting a mix of adjust condition (Rewrite Cond) tests nearby a differentiating rule (Rewrite Rule) if the past conditions pass. As a rule, these guidelines have to be set at whatever point after the Rewrite Engine on line in the.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-grey 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\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Modifying_non-existing_associations_with_index_Php\" >Modifying non-existing associations with index. Php<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#What_to_change_in_the_models_under\" >What to change in the models under?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Redirecting_all_URLs\" >Redirecting all URLs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Redirecting_a_singular_URL\" >Redirecting a singular URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Redirect_to_a_local_site_record\" >Redirect to a local site record<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Redirect_to_an_external_site_report\" >Redirect to an external site report<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#The_essential_way\" >The essential way<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#The_resulting_way\" >The resulting way<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Instances_of_sidetracks\" >Instances of sidetracks<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Divert_from_an_index_to_a_HTML_record\" >Divert from an index to a HTML record<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Divert_from_an_indexhtml_document_to_an_alternate_registry\" >Divert from an index.html document to an alternate registry<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Divert_from_indexhtml_to_defaulthtml\" >Divert from index.html to default.html<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Divert_a_neighborhoodprivate_registry_to_another_sites_private_index\" >Divert a neighborhood\/private registry to another site&#8217;s private index<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Using_Regular_Expressions\" >Using Regular Expressions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Redirecting_flop_messages\" >Redirecting flop messages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Thusly_packing_a_division\" >Thusly packing a division<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Taking_out_www_in_the_URL\" >Taking out www in the URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/arzhost.com\/blogs\/rewrite-rule-index-php\/#Revamping_a_URL\" >Revamping a URL<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Modifying_non-existing_associations_with_index_Php\"><\/span><strong>Modifying non-existing associations with index. Php <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The going with diverts associates with records or envelopes that don&#8217;t exist to index. <a href=\"https:\/\/en.wikipedia.org\/wiki\/PHP\" target=\"_blank\" rel=\"noopener\">Php<\/a>. Regardless, if the report or record exists, it stacks normally:<\/p>\n<pre><code>&lt;If Module mod_rewrite.c&gt;\r\n\r\nRewrite Engine On\r\n\r\nRewrite Base\/\r\n\r\nRewrite Rule ^index\\. php$ - [L]\r\n\r\nRewrite Cond %{REQUEST_FILENAME}! - f\r\n\r\nRewrite Cond %{REQUEST_FILENAME}! - d\r\n\r\nRewrite Rule. \/index. Php [L]\r\n\r\n&lt;\/If Module&gt;<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"What_to_change_in_the_models_under\"><\/span><strong>What to change in the models under? <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The models under can be gone into your .htaccess record definitely as showed up. Essentially attempt to change the certifiable path to the record so the .htaccess report acknowledges where it&#8217;s found. Furthermore, if you see the space example.com, change this to your own region name.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Redirecting_all_URLs\"><\/span><strong><u>Redirecting all URLs <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The going with line redirects all URLs on your site to the new site.<\/p>\n<pre><code>Redirect 301\/https:\/\/example.com\/<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Redirecting_a_singular_URL\"><\/span><strong><u>Redirecting a singular URL <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Using Redirect in an .htaccess record enables you to redirect customers from an old page to another page without keeping the old page. For example, expecting you use index.html as your rundown record and, later rename index.html to home.html, you could set up a redirect to send customers from index.html to home.html. For example:<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Redirect_to_a_local_site_record\"><\/span><strong><u>Redirect to a local site record <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>Redirect\/way\/to\/old\/record\/old.html\/way\/to\/new\/report\/new.html<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Redirect_to_an_external_site_report\"><\/span><strong><u>Redirect to an external site report <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>Redirect\/way\/to\/old\/record\/old.html https:\/\/www.example.com\/new\/archive\/new.html<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"The_essential_way\"><\/span><strong>The essential way <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The chief route to the old record ought to be a local UNIX way, NOT the full way. Along these lines, if the .htaccess report is in the inventory\/example.com, you would avoid\/home\/username\/example.com in the local UNIX way. The primary\/addresses the example.com list. In case the old report was around there, you would follow the\/with the old record name.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_resulting_way\"><\/span><strong>The resulting way <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The second path to the new record can be a close by UNIX way, yet can moreover be a full URL to association with a page on a substitute laborer or a comparable specialist.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Instances_of_sidetracks\"><\/span><strong>Instances of sidetracks <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Divert_from_an_index_to_a_HTML_record\"><\/span><strong><u>Divert from an index to a HTML record <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>RedirectMatch 301 ^\/blog\/about\/blog\/about.html<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Divert_from_an_indexhtml_document_to_an_alternate_registry\"><\/span><strong><u>Divert from an index.html document to an alternate registry <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>Divert\/index.html\/new\/<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Divert_from_indexhtml_to_defaulthtml\"><\/span><strong><u>Divert from index.html to default.html <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>Divert\/index.html\/default.html<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Divert_a_neighborhoodprivate_registry_to_another_sites_private_index\"><\/span><strong><u>Divert a neighborhood\/private registry to another site&#8217;s private index <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>Divert\/private\/https:\/\/www.example.com\/private\/<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Using_Regular_Expressions\"><\/span><strong>Using Regular Expressions <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you need to use a Regular Expression to redirect something, use the RedirectMatch command:<\/p>\n<pre><code>RedirectMatch \"^\/oldfile\\.html\/?$\" \"https:\/\/example.com\/newfile.php\"<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Redirecting_flop_messages\"><\/span><strong><u>Redirecting flop messages <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can in like manner redirect 404 bumbles. Maybe than throwing a 404 page, this derails the greeting page of the site.<\/p>\n<pre><code>Error Document 404 https:\/\/example.com\/<\/code><\/pre>\n<p>Redirecting an old list to new library This distracts in an old library (\/blog\/records) to another account (\/narratives). The report should exist in the new list to work.<\/p>\n<pre><code>Rewrite Rule ^blog\/records\/(.*)$\/newarchives\/$1 [R=301,NC,L]\r\n \tRedirect non-existing pages to index.php<\/code><\/pre>\n<p>If a visitor attempts to get to a page that doesn&#8217;t exist, they are given a 404 bungle. You can rather redirect any sales to a non-existing page to your index.php record (or any document archive) by adding the going with code in your .htaccess:<\/p>\n<pre><code>decisions +SymLinksIfOwnerMatch\r\n \tRewriteEngine On\r\n \tRewriteCond %{REQUEST_FILENAME}! - f\r\n \tRewriteCond %{REQUEST_FILENAME}! - d\r\n \t\/index.php [L]<\/code><\/pre>\n<p>In case your rundown page isn&#8217;t index.php, just change the last line to your certifiable rundown record. By then the visitor is redirected back to your greeting page.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Thusly_packing_a_division\"><\/span><strong><u>Thusly packing a division <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This model redirects the ROOT region&#8217;s URL to any subdivision. In this model, it subsequently stacks example.com\/subdir1:<\/p>\n<pre><code>RewriteEngine on\r\n \tRewriteRule ^$\/subdir1\/[L]\r\n \tDriving www in the URL\r\n \tRewriteEngine On\r\n \tRewriteCond %{HTTP_HOST} ^example.com\r\n \tRewriteRule (. *) https:\/\/www.example.com\/$1 [R=301, L]<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Taking_out_www_in_the_URL\"><\/span><strong><u>Taking out www in the URL <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code>RewriteEngine On\r\n \tRewriteCond %{HTTP_HOST} ^www.example.com\r\n \tRewriteRule (. *) https:\/\/example.com\/$1 [R=301, L]<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Revamping_a_URL\"><\/span><strong><u>Revamping a URL <\/u><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This model renovation a URL to another URL. This renovations example.com\/1.html to example.com\/abc.php? id? id=1.<\/p>\n<pre><code>RewriteEngine On\r\n \tRewriteRule ^ ([0-9] +) .html\/abc.php? id? id=$1 [QSA, L]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Rewrite Rule proves the request. shape is an ordinary clarification that organizes with the ideal string from the URL, which is what the watcher types in the program. substitution is the way to the real URL, for example the method of the record Apache employees. flags are optional limits that can change how the standard [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7682,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"table_tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":5,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":7683,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/280\/revisions\/7683"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/7682"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=280"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/table_tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}