Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You seem to be confused with how URLs and rewriting works. The notion that <em>"I need to rewrite <strong>this2</strong> to <strong>this1</strong> "</em> means:</p> <ol> <li>Someone either enters <strong>this2</strong> in their address bar or clicks on a <strong>this2</strong> link.</li> <li>Server sees a request for <strong>this2</strong></li> <li>Server has a set of rules to internally rewrite the request from <strong>this2</strong> to <strong>this1</strong></li> <li><strong>this1</strong> is served to the browser</li> </ol> <p>Note that the important concept in all of this is that <strong>the browser requests for the "this2" link</strong>, and <strong>the server internally rewrites the request to "this1"</strong>. But this is probably not what you want at all, because then you'd be taking the ugly URLs and rewriting them to the nice looking URLs, sort of missing the point of friendly looking URLs.</p> <p>Too often, especially around here, people ask for stuff like "I want to change this url to this url", or asking for rewrite when there's a 2 step redirect process. This is the 2nd step (which you are not asking for at all) which takes <strong>this1</strong> and <em>redirects the browser</em> to <strong>this2</strong> so that the url address bar changes to <strong>this2</strong>:</p> <ol> <li>Someone either enters <strong>this1</strong> in their address bar or clicks on a <strong>this1</strong> link.</li> <li>Server sees a request for <strong>this1</strong></li> <li>Server has a set of rules to <em>externally redirect the browser</em> to <strong>this2</strong>.</li> <li>The browser's address bar now says <strong>this2</strong></li> <li>The browser requests <strong>this2</strong></li> <li>Server sees a request for <strong>this2</strong></li> <li>Server has a set of rules to internally rewrite the request from <strong>this2</strong> to <strong>this1</strong></li> <li><strong>this1</strong> is served to the browser</li> </ol> <p>So this whole round-about convolution is <em>just</em> so when the browser tries to go to <strong>this1</strong>, it gets redirected to <strong>this2</strong> but still actually gets served the content from <strong>this1</strong>.</p> <p>So I assume this must be what you want. Try putting this in your htaccess file:</p> <pre><code>RewriteEngine On # check if the actual request if for "this1" RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /profiles/tutors/index.php\?tutorCode=([0-9]+)&amp;tutorName=([^&amp;]+)&amp;?([^\ ]+) # redirect to "this2" RewriteRule ^profiles/tutors/index\.php /%1/%2/?%3 [R=301,L,NE] # now rewrite "this2" back to "this1" RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([0-9]+)/(.+)/$ /profiles/tutors/index.php?tutorCode=$1&amp;tutorName=$2 [L,QSA] </code></pre> <p>Note that the <code>city</code> parameter is never being encoded in the friendly URL, so it's left as part of the query string. You could change this so that the friendly URL looks like: <code>/id/name/city/</code> instead of just <code>/id/name/</code>, that modification should be trivial.</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