Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a number of things wrong with the .htaccess code generated by that website.</p> <ul> <li>The period character (<code>.</code>) should be escaped on the left hand side of RewriteRule directives - i.e. <code>\.php</code>.</li> <li>The query string isn't taken into account (This is the primary cause of your problem which I explain below).</li> <li>There's no indication of the type of redirect used. Temporary? Permanent?</li> <li>There's no <code>RewriteBase</code> directive. Not essential as <code>/</code> is taken as the default, but for readability's sake, I tend to use it.</li> </ul> <p>Rewrite directives notably take into account only the REQUEST_URI component. The below is from the <a href="http://httpd.apache.org/docs/current/mod/mod_rewrite.html" rel="nofollow">mod_rewrite manual page</a>.</p> <blockquote> <p>REQUEST_URI The path component of the requested URI, such as "/index.html". This notably excludes the query string which is available as as its own variable named QUERY_STRING.</p> </blockquote> <p>The following code is explained in the comments, and debugging info from here can be found below.</p> <pre><code># Enable rewrite engine http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteengine RewriteEngine On # Sets the base URL for per-directory rewrite http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase RewriteBase / # Match the regular expression ^pname=...$ with the QUERY_STRING variable as the subject # Query string starts with pname (`^`). # Matches exactly pname=overviewvideos. # Must end with overviewvideos (`$`) RewriteCond %{QUERY_STRING} ^pname=overvidevideos$ # If the above condition is met, redirect to the 2nd parameter. # Note the escaped period (\.) # Note the status code 302 (Found, temporary) Can be 301 for permanent etc. # Note the L flag - this prevents further rules being processed if the conditions are met. (L for Last) # Note that at this stage we are back to matching the REQUEST_URI, so just allvideos.php in our regular expression. Must start and end with the string allvideos.php RewriteRule ^allvideos\.php$ allvideos.php?pname=Overview%20Videos [R=302,L] </code></pre> <p>Input URL: <a href="http://www.yoursite.com/allvideos.php?pname=overvidevideos" rel="nofollow">http://www.yoursite.com/allvideos.php?pname=overvidevideos</a></p> <pre><code>RewriteCond %{QUERY_STRING} ^pname=overvidevideos$ This condition was met RewriteRule ^allvideos\.php$ allvideos.php?pname=Overview%20Videos [R=302,L] This rule was met, the new url is http://www.yoursite.com/allvideos.php?pname=Overview%20Videos Test are stopped, because of the R in your RewriteRule options. A redirect will be made with status code 302 </code></pre> <p>Output URL: <a href="http://www.yoursite.com/allvideos.php?pname=Overview%20Videos" rel="nofollow">http://www.yoursite.com/allvideos.php?pname=Overview%20Videos</a></p> <p>To repeat the rules, you can duplicate the lines beginning RewriteCond and RewriteRule.</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