Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, you need two rules. One rule to redirect the client to a clean URL and another to internally rewrite the pretty URL to the real content via <code>index.php</code>.</p> <p>Assuming the <code>index.php</code> and <code>.htaccess</code> is in a directory <code>cdi</code> </p> <pre><code>RewriteEngine on # prevent endless loop RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule ^ - [L] # redirect the client RewriteCond %{QUERY_STRING} URL=pages/(.+?)\.php RewriteRule ^index\.php$ /cdi/%1? [R,L] # exclude rewriting all files located in /cdi/files RewriteCond %{REQUEST_URI} !^/cdi/files/ # rewrite to real content RewriteRule ^.*$ /cdi/index.php?URL=pages/$0.php [L] </code></pre> <p><strong>Update</strong>:</p> <p>When the request is <code>/cdi/index.php?URL=pages/abc.php</code>, the second rule extracts the needed <code>URL</code> part and redirects the client to the new URL path. The client then requests the new URL <code>/cdi/abc</code> and the third rule takes this and does an internal rewrite to the real content.</p> <p>This all works fine as it should, but would rewrite and redirect indefinitely. To break this endless rule, the first rule checks the environment <code>%{ENV:...}</code>, if the request was already redirected <code>REDIRECT_STATUS</code> and then stops the cycle with the <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule" rel="nofollow"><code>RewriteRule</code></a> </p> <pre><code>RewriteRule ^ - [L] </code></pre> <p>which matches everything <code>^</code> and does no <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rhs" rel="nofollow">substitution</a>, but ends the rewrite cycle with the flag <a href="http://httpd.apache.org/docs/current/rewrite/flags.html#flag_l" rel="nofollow"><code>[L]</code></a></p> <p>Instead of using the system provided environment <code>STATUS</code>/<code>REDIRECT_STATUS</code>, you can also set a variable yourself with the flag <a href="http://httpd.apache.org/docs/current/rewrite/flags.html#flag_e" rel="nofollow"><code>E=SEO:1</code></a> for example, and then test for this variable with </p> <pre><code>RewriteCond %{ENV:REDIRECT_SEO} 1 </code></pre> <p>For the <code>REDIRECT_</code> prefix, see <a href="http://httpd.apache.org/docs/current/custom-error.html#variables" rel="nofollow">Available Variables</a>.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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