URL without trailing slash makes Apache look in non-SSL DocumentRoot

3,055

An alternative fix would be to enforce the trailing slash on the end of your URLS - this would have the benefit of preventing duplicates if your not using Rel Canonical.

SOURCE

This will redirect all requests without a tailing / to the URL with the slash on the end. (note within the 2nd part of the bracket is those file extensions to ignore.. Since it wouldn't make sense to enforce / on a picture URL.

RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$

RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

Share:
3,055
Leahcim
Author by

Leahcim

Updated on September 18, 2022

Comments

  • Leahcim
    Leahcim over 1 year

    I'm following a PHP tutorial which is teaching about $_POST and it had me create an exercise with two pages. On the first page (Form page) it creates a form where a user enters Username and Password. Once they click submit, it opens on the second page (process.php) where the Username and Password should be displayed as a result of using $_Post. However, when I click submit on the first page, it takes me to the second page where only the ":" in the Echo statement is displayed. No username, no password.

    Any ideas? I've copied the form page and the process.php below.

    Form page
    
    <html>
    <head>
    <title>encode</title>
    </head>
    <body>
    <form action="process.php" method="post">
         Username: <input type="text" name="username" value="" />
         <br/>
         Password: <input type="password" name="password" value=""/>
         <br/>
         <input type="submit" name="submit" value="Submit"/>
         </form>
    </body>
    </html>
    

    Process.php

    <html>
    <head>
    <title>encode</title>
    </head>
    <body>
     <?php
    $username = $_Post['username'];
    $password = $_Post['password'];
    
    echo "{$username}: {$password}";
    ?>
    
    </body>
    </html>
    
  • Lightness Races in Orbit
    Lightness Races in Orbit over 12 years
    It is not about who is "first"!
  • alex
    alex over 12 years
    @Tomalak It does to some degree. Should I answer a day old question with an existing answer reworded?
  • Lightness Races in Orbit
    Lightness Races in Orbit over 12 years
    @alex: 15 seconds != 1 day. Plagiarism and "who beat you to the punch" are not the same thing!
  • alex
    alex over 12 years
    @Tomalak Sometimes it can be difficult to differentiate the two.
  • Lightness Races in Orbit
    Lightness Races in Orbit over 12 years
    @alex: I've never had a problem differentiating between a day and 15 seconds. But maybe that's just me!
  • alex
    alex over 12 years
    @Tomalak I was referring to the latter Plagiarism and "who beat you to the punch".
  • Lightness Races in Orbit
    Lightness Races in Orbit over 12 years
    @alex: It was more fun to pretend that you were referring to the initial comparison.
  • ThisSuitIsBlackNot
    ThisSuitIsBlackNot almost 11 years
    Thanks bybe, this looks like it will come in handy even if I don't use it for this particular issue.