Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This rule will apply to every URL pointing to a PHP file, stripping off the latter and issuing a redirect to the remainder.</p> <pre><code>RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\/[^/]+\.php\ HTTP/ RewriteRule ^(.*)/[^/]+\.php$ http://%{HTTP_HOST}/$1 [R=301,L] </code></pre> <p><strong>EDIT</strong><br> @Ashley Briscoe: I think you are messing things up here a bit. Say the initial URL your client is requesting is <code>http://www.example.com/products/products.php</code>. This will be rewritten by the above rule to <code>http://www.example.com/products/</code>. </p> <p>Since now the rewritten URL is pointing to a directory (the trailing slash indicates that) rather than a file resource, Apache is trying to serve the <a href="http://httpd.apache.org/docs/2.2/mod/mod_dir.html" rel="nofollow">directory index file</a> (e.g. index.html or index.php) in case <strong>mod_dir</strong> is being used (we can safely assume it is).</p> <p>The <code>403 Forbidden</code> response you get now indicates that the user your web server is running as DOES NOT have sufficient priviledges to read the directory index file and/or open its containing folder. </p> <p>To resolve this, you need to make sure that there actually exists a directory index file (thus renaming <code>products.php</code> to <code>index.php</code> within the products directory) and that the web server has the permission to read that file. </p> <p><strong>EDIT 2</strong><br> Regarding your last comment: If renaming isn't an option then you would have to let Apache know what file it should serve instead. Thus add another rule, like so:</p> <pre><code>RewriteEngine on RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\/[^/]+\.php\ HTTP/ RewriteRule ^(.*)/[^/]+\.php$ http://%{HTTP_HOST}/$1 [R=301,L] RewriteRule ^products/?$ /products/products.php [L] </code></pre>
 

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