Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get mod_rewrite to both remove file extensions and redirect certain URLs?
    primarykey
    data
    text
    <p>So I'm trying to get mod_rewrite to do a few different things, and I'm not quite there with it. I'd like to:</p> <ol> <li>Remove file extensions from the URLs (in this case, .shtml)</li> <li><p>Rewrite certain URLs like so:</p> <pre><code>/dashboard -&gt; /ui/dashboard/index.shtml /dashboard/ -&gt; /ui/dashboard/index.shtml /dashboard/list -&gt; /ui/dashboard/list.shtml /dashboard/list/ -&gt; /ui/dashboard/list.shtml /workspace -&gt; /ui/workspace/index.shtml /workspace/ -&gt; /ui/workspace/index.shtml /account/manage -&gt; /ui/account/manage.shtml /account/manage/ -&gt; /ui/account/manage.shtml </code></pre></li> <li><p>Either add or remove a trailing slash ( I don't care which, as long as it's consistent)</p></li> </ol> <p>What I currently have gets me about 90% of the way there. In my .htaccess file, I've got the following:</p> <pre><code>DirectoryIndex index.shtml index.html index.htm &lt;IfModule mod_rewrite.c&gt; Options +FollowSymlinks RewriteEngine On RewriteBase / # Get rid of the /ui/ in the URLs RewriteRule ^(account|workspace|dashboard)([a-zA-Z0-9\-_\.\/]+)?$ /ui/$1$2 [NC,L] # Add the trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$ RewriteRule ^(.*)$ $1/ [R=301,L] # Remove the shtml extension RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.shtml -f RewriteRule ^([^\.]+)/$ $1\.shtml &lt;/IfModule&gt; </code></pre> <p>Now the issues I'm running into are twofold:</p> <p>First, if I try to access one of the index pages outlined in the directories listed in step 2 above, as long as I do it with a trailing slash, it's fine, but if I omit the trailing slash, the URL rewrites incorrectly (the page still loads, however). For example</p> <pre><code>/dashboard/ remains /dashboard/ in the address bar. /dashboard rewrites to /ui/dashboard/ in the address bar. </code></pre> <p>How can I get these index.shtml pages to keep the address bar consistent?</p> <p>Second, when I try to access a page other than the directory index in one of the rewritten directories, and I include a trailing slash, it gives me a 404 error. For instance:</p> <pre><code>/dashboard/list/ </code></pre> <p>throws the 404 error:</p> <pre><code>The requested URL /ui/dashboard/list.shtml/ was not found on this server. </code></pre> <p>Any help to get this working properly that you can offer is much appreciated.</p>
    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.
    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