This article describes how to direct incoming traffic coming from "fake" URLs of this type:


to a PHP file that "really" uses URLs of this type:


Here is the example code used in the htaccess file:

RewriteEngine on
RewriteRule ^article-(.*).php$ ./article_show_friendly.php?url=$1

However, my pages have multiple queries in their URLs. How do I make this work for them?


(I want to use the tit parameter as the main part of the URL.)


1 Answer 1


I want to use the "tit" parameter as the main part of the URL.

If you literally only want to use that one parameter, and you don't need to pass the other parameters in the URL (ie. they can be deduced from that one parameter), then it's exactly the same as your first example. You would have a "pretty" (fake) URL of the form:


(No need for the .php extension on the URL, unless you explicitly want it?) Which is then internally rewritten with something like the following in the /keyboard/.htaccess file:

RewriteRule ^([\w-]+)$ keyboard-chart.php?gam=141&sty=16&lay=1&tit=$1 [L]

In the above example, the gam, sty and lay parameters are hard-coded in the RewriteRule substitution. This assumes that given a tit parameter of sid-meiers-alpha-centauri-smac-1, you know what these other parameter values are.

However, if that is not the case and these other parameters can also vary, then these must also be passed in the "pretty" URL, since they cannot be deduced from the single tit parameter. This can be achieved using the same principle as above: define a capturing group (ie. parenthesised sub pattern) in the RewriteRule pattern (regex) for each parameter and use a corresponding backreference ($1..$9) in the substitution. For example, given a URL of the form:


Then this can be internally rewritten with something like the following in the /keyboard/.htaccess file:

RewriteRule ^(\d+)/(\d+)/(\d)/([\w-]+)$ keyboard-chart.php?gam=$1&sty=$2&lay=$3&tit=$4 [L]

coming from "fake" URLs

I know what you mean, but they aren't really fake. They are the "pretty" URLs, or simply "URLs". It's just that they don't directly map to a file system resource, without some URL rewriting. (By "fake" I immediately thought you were referring to URLs that didn't exist!)

SEO Friendly URLs

The article that you link to makes repeated reference to "SEO friendly URLs". To be clear, these are not strictly SEO-friendly. Search engines don't really care. "Pretty" URLs like this are primarily for the benefit of users, not search engines, and can help with click-through rates, but they don't directly help with ranking.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.