{"id":45,"date":"2004-05-08T19:58:17","date_gmt":"2004-05-08T17:58:17","guid":{"rendered":"http:\/\/frenchfragfactory.net\/ozh\/archives\/2004\/05\/08\/apache-and-the-trailing-slash-problem\/"},"modified":"2007-05-10T00:03:13","modified_gmt":"2007-05-09T22:03:13","slug":"apache-and-the-trailing-slash-problem","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2004\/05\/apache-and-the-trailing-slash-problem\/","title":{"rendered":"Apache and the trailing slash problem"},"content":{"rendered":"<p>On badly configured Apaches (like on errr&#8230; my host :), URLs referecing directories and lacking a trailing slash (like <em>\/mydir<\/em> instead of <em>\/mydir<strong>\/<\/strong><\/em>) lead to an error : the webserver looks for a <em>file<\/em> named mydir instead of a directory.<\/p>\n<p>After some googling and lots of testing, I&#39;ve come up with a solution. This should even work on Apaches with virtual hosts enabled and bad <em>ServerName<\/em> directive.<\/p>\n<p>Put this in <em>.htaccess<\/em> in your document root (given example is for my site of course, replace the server name with yours)<\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">code<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"code\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">RewriteEngine &nbsp;on<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">RewriteBase &nbsp; &nbsp;\/<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">RewriteCond &nbsp; &nbsp;%{REQUEST_FILENAME} &nbsp;-d<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">RewriteRule &nbsp; &nbsp;^(.+[^\/])$ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; http:\/\/frenchfragfactory.net\/$1\/ &nbsp;[R=301,L]<\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n<p>Of course, you need mod_rewrite and the ability to override these settings in your .htaccess file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to solve the &quot;trailing slash&quot; problem in misconfigured Apache<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[56,2,194,195,11],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","tag-apache","tag-code","tag-htaccess","tag-mod_rewrite","tag-web"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}