{"id":8577,"date":"2014-11-09T19:33:49","date_gmt":"2014-11-09T19:33:49","guid":{"rendered":"https:\/\/wp.okra.host\/article\/htaccess-guide\/"},"modified":"2021-03-07T14:30:50","modified_gmt":"2021-03-07T13:30:50","slug":"htaccess-guide","status":"publish","type":"ht_kb","link":"https:\/\/kb.okra.host\/de\/article\/htaccess-guide\/","title":{"rendered":".htaccess-Leitfaden"},"content":{"rendered":"<h2 id=\"overview\" >Overview<\/h2>\n<p>An .htaccess file contains directives that the web server will apply to a collection of resources before a page is displayed. For example, a .htaccess file may change <a title=\"Changing PHP settings\" href=\"https:\/\/kb.okra.host\/php\/changing-php-settings\/\">PHP configuration<\/a>, deny\u00a0access, change the page displayed, and even redirect a resource to another URL. These are denoted by a\u00a0<em>directive<\/em>. A directive consists of a directive name and value, such as <code>DirectoryOptions +Indexes<\/code> or\u00a0<code>php_flag display_errors on<\/code>.<\/p>\n<h2 id=\"directive-precedence\" >Directive precedence<\/h2>\n<p>Before changing how the web server works, it&#8217;s important to know how these rules are applied. Before a request is processed, the server looks for a\u00a0<code><\/code>file called\u00a0<code>.htaccess<\/code> in the directory in which <a title=\"Where is site content served from?\" href=\"https:\/\/kb.okra.host\/web-content\/where-is-site-content-served-from\/\">content is served<\/a>. Any directives in this file are applied. The server will then backtrack down each directory until it reaches\u00a0<code>\/var\/www<\/code> applying whatever directives are present in whatever .htaccess files it finds along the way.<\/p>\n<blockquote>\n<h3 id=\"example\" >Example<\/h3>\n<p>A page is served from\u00a0<code>\/var\/www\/mydomain.com<\/code>. .htaccess files are located present as\u00a0<code>\/var\/www\/mydomain.com\/.htaccess<\/code> and\u00a0<code>\/var\/www\/.htaccess<\/code>. First, rules in\u00a0<code>\/var\/www\/mydomain.com\/.htaccess<\/code> are applied. Then, any rules in\u00a0<code>\/var\/www\/.htaccess<\/code> are applied\u00a0overriding any rules present under\u00a0<code>mydomain.com\/<\/code>.<\/p>\n<p><em>Be careful with addon domain locations!\u00a0<\/em>.htaccess can be located under\u00a0<code>\/var\/www<\/code> to apply global configuration to any subdomain or\u00a0domain located under\u00a0<code>\/var\/www<\/code>.<\/p>\n<\/blockquote>\n<h2 id=\"setting-directives\" >Setting directives<\/h2>\n<p>Create a plain-text file named\u00a0<code>.htaccess<\/code>\u00a0that will be uploaded in the <a title=\"Where is site content served from?\" href=\"https:\/\/kb.okra.host\/web-content\/where-is-site-content-served-from\/\">document root<\/a> for the subdomain or domain whose behavior you would like to modify.<\/p>\n<blockquote>\n<p>You may also create an empty plain-text file <a title=\"Creating empty files\" href=\"https:\/\/kb.okra.host\/control-panel\/creating-empty-files\/\">within the control panel<\/a>\u00a0under <strong>Files<\/strong> &gt;\u00a0<strong>File Manager<\/strong>.\u00a0You may then edit the file by clicking on\u00a0the\u00a0<strong>Edit<\/strong> action in the <em>Actions<\/em> column\u00a0to make changes from your browser.<\/p>\n<\/blockquote>\n<p>Each directive is one-line long and placed on a separate line. For example, these are all <em>valid<\/em>\u00a0directives:<\/p>\n<ul>\n<li><code>Options +Indexes<\/code><\/li>\n<li><code>RewriteCond %{HTTPS} ^ON$<\/code><\/li>\n<li><code>php_value error_reporting 99999<\/code><\/li>\n<li><code>PassengerEnabled On<\/code><\/li>\n<\/ul>\n<p>These are all <i>invalid:<\/i><\/p>\n<ul>\n<li>Options\n<ul>\n<li>Reason: <span style=\"color: #ff0000\">missing option\u00a0values<\/span><\/li>\n<\/ul>\n<\/li>\n<li><code><\/code>php_value error_reporting display_errors on\n<ul>\n<li>Reason:\u00a0<span style=\"color: #ff0000\">extraneous PHP <a style=\"color: #ff0000\" title=\"Changing PHP settings\" href=\"https:\/\/kb.okra.host\/php\/changing-php-settings\/\">configuration directives<\/a><\/span><\/li>\n<\/ul>\n<\/li>\n<li>RewriteCond %{HTTPS} ^ON$ RewriteRule ^(.*)$ https:\/\/mydomain.com\/$1 [R,L]\n<ul>\n<li>Reason: <span style=\"color: #ff0000\">each directive (RewriteCond, RewriteRule) must reside on its own line<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-family: monospace\">PassengerEnabled\u00a0yes<\/span>\n<ul>\n<li>Reason: <span style=\"color: #ff0000\">&#8220;yes&#8221; is not an acceptable\u00a0value for PassengerEnabled<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2 id=\"handling-errors\" >Handling Errors<\/h2>\n<p>Sometimes a directive may be improperly entered into your .htaccess file. In such cases, the web site will fail to display and an\u00a0<em>Internal Server Error<\/em>\u00a0will be generated. You can refer to\u00a0<code><a title=\"Accessing web page views and error messages\" href=\"https:\/\/kb.okra.host\/web-content\/accessing-page-views-and-error-messages\/\">error_log<\/a><\/code>\u00a0for a detailed explanation of what directive was rejected and for what particular reason.<\/p>\n<h2 id=\"common-directives\" >Common Directives<\/h2>\n<table style=\"width: 100%;float: left;margin: 1em;margin-left: 0\" border=\"0\">\n<thead>\n<tr>\n<th>Directive Name<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<th>Documentation<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>php_value<\/td>\n<td>Sets PHP runtime configuration<\/td>\n<td>php_value\u00a0upload_max_filesize 32M<\/td>\n<td>Okra Host KB: <a title=\"Changing PHP settings\" href=\"https:\/\/kb.okra.host\/php\/changing-php-settings\/\">Changing PHP Settings<\/a><\/td>\n<\/tr>\n<tr>\n<td>RewriteBase<\/td>\n<td>Anchors a rewrite rule to the current directory<\/td>\n<td>RewriteBase \/<\/td>\n<td>Apache Documentation:\u00a0<a href=\"http:\/\/httpd.apache.org\/docs\/2.2\/rewrite\/\">Apache mod_rewrite<\/a><\/td>\n<\/tr>\n<tr>\n<td>Options<\/td>\n<td>Sets directory-specific options<\/td>\n<td>Options +Indexes<\/td>\n<td>Apache Documentation: <a href=\"http:\/\/httpd.apache.org\/docs\/current\/mod\/core.html#options\">core<\/a><\/td>\n<\/tr>\n<tr>\n<td>PassengerEnabled<\/td>\n<td>Enable Rails, node.js, and Python autoloading<\/td>\n<td>PassengerEnabled On<\/td>\n<td><a href=\"https:\/\/www.phusionpassenger.com\/documentation\/Users%20guide%20Apache.html#PassengerEnabled\">Phusion Documentation<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Overview An .htaccess file contains directives that the web server will apply to a collection of resources before a page is displayed. For example, a .htaccess file may change PHP configuration, deny\u00a0access, change the page displayed, and even redirect a resource to another URL. These are denoted by a\u00a0directive. A&#8230;<\/p>","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[60],"ht-kb-tag":[],"class_list":["post-8577","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-guides"],"_links":{"self":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/comments?post=8577"}],"version-history":[{"count":1,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8577\/revisions"}],"predecessor-version":[{"id":8578,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb\/8577\/revisions\/8578"}],"wp:attachment":[{"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/media?parent=8577"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-category?post=8577"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.okra.host\/de\/wp-json\/wp\/v2\/ht-kb-tag?post=8577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}