Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_rewrite: add trailing slash?
    primarykey
    data
    text
    <p>I am using a .htaccess file to direct requests for a directory to a custom php file that provides info about that directory (and i want the url displayed by the browser to not change).</p> <p>Here is the relevant part of the .htaccess file.</p> <pre><code>RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /myphp.php?url=%{REQUEST_URI} [QSA,L] </code></pre> <p>This works well if you go to a directory and include a trailing slash:</p> <pre><code>http://domain.com/path/ </code></pre> <p>But without the trailing slash, it doesn't</p> <pre><code>http://domain.com/path </code></pre> <p>The url (shown in the browser) turns into:</p> <pre><code>http://localhost:8888/path/?url=/path </code></pre> <p>I've tried fixing this by adding a rule above this rule:</p> <pre><code>RewriteCond %{REQUEST_FILENAME} -D RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ $1/ [L] </code></pre> <p>But that isn't working for me.</p> <p>How can I get .htaccess to add the trailing slash if it is omitted and then act just as if it had been there?</p> <p>Thank you</p> <p>Update: As requested, here is the whole thing.</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On #force trailing slashes on real directories RewriteCond %{REQUEST_FILENAME} -D RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ $1/ [L] #use the directory viewer on directories without an index page RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /myphp.php?url=%{REQUEST_URI} [QSA,L] &lt;/IfModule&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload