Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Are you trying to do something like this?</p> <pre><code>RewriteRule ^([^/]+)/([^/]+)/? /index.php?site=$1&amp;category=$2 [L] </code></pre> <p>This will make it so when you go to <a href="http://domain.com/food/beef" rel="nofollow">http://domain.com/food/beef</a> the request gets rewritten to "/index.php?site=food&amp;category=beef" internally and index.php is used to serve the original request. The browser's location bar will still say "http://domain.com/food/beef". </p> <p>If you want the location bar to say <a href="http://domain.com/index.php?site=food&amp;category=beef" rel="nofollow">http://domain.com/index.php?site=food&amp;category=beef</a> then add an "R," to the "[L]". If this is backwards and you want it so when someone enters <a href="http://domain.com/index.php?site=food&amp;category=beef" rel="nofollow">http://domain.com/index.php?site=food&amp;category=beef</a> in the location bar, and the request gets rewritten to "/food/beef" internally on the server, then you need to parse out the query string using RewriteCond:</p> <pre><code>RewriteCond %{QUERY_STRING} ^site=([^&amp;]+)&amp;category=([^&amp;]+) RewriteRule ^index.php /%1/%2? [L] </code></pre> <p>The same thing applies with the "R" causing a browser redirect like the first example. If you want the location bar to change to <a href="http://domain.com/food/beef" rel="nofollow">http://domain.com/food/beef</a> then the brackets should look like: <code>[L,R]</code>. Note that you need a <strong>?</strong> at the end of the target in the rule, so that query strings don't get thrown in. That is why in your google example, the query string is being appended. </p> <p>EDIT:</p> <h2>Seeing as you just wanted to change what's in the browser's location bar and not where the content is:</h2> <p>You need to <strong>re-rewrite</strong> what the 2nd rule above has rewritten <strong>BACK</strong> to index.php, but without a redirect. In order to keep the 2 rules from looping indefinitely because one rule rewrites to the other rule and vice versa, you need to add a flag somewhere to keep the 2nd rule above from redirecting you over and over again.</p> <p>So combining the two, you'll have this:</p> <pre><code>RewriteRule ^([^/]+)/([^/]+)/? /index.php?site=$1&amp;category=$2&amp;redirected [L] RewriteCond %{QUERY_STRING} !redirected RewriteCond %{QUERY_STRING} ^site=([^&amp;]+)&amp;category=([^&amp;]+) RewriteRule ^index.php /%1/%2? [L,R=301] </code></pre> <p>Note the <code>redirected</code> parameter in the query string. This gets inserted when someone tries to access the clean version of the url, e.g. "/food/beef". internally, it gets rerouted to index.php but since the rule doesn't have a "R", the browser's location bar doesn't change.</p> <p>The second rule now checks if the request contains the <code>redirected</code> param in the query string. If it doesn't, that means someone entered in their browser's location bar the index.php url, so redirect the browser to the clean version.</p>
 

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