Forum Moderators: phranque
[webmasterworld.com...]
I read and got it but just still one missing connection here, so i will write an example and correct me if i am wrong please..
lets say ive link that was originaly
<a href="bmw.php?cat=$cat&id=$id">BMW</a>
so after applying RewriteRules it would look like
RewriteRule ^/bmw/([0-9]*),([0-9]*)$ /bmw.php?cat=$1&id=$2
-------------------------------------------
I think that was right so far so now my confusion is in the php file how should the link look like and should i create and empty folder called for ex. bmw
and would the link look like this..
<a href="bmw">BMW</a>
thanks
RewriteRule ^/bmw-([0-9]+)-([0-9]+)$ /bmw.php?cat=$1&id=$2 [L]
If you are interested in SEO aspects, use hyphens, not underscores, and certainly not commas (they are restricted characters and will have to be encoded as '%2C', which is ugly).
To prevent your 'unfriendly' URLs from being indexed, or to replace those previously indexed, add another rule:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /bmw\.php\?cat=([0-9]+)&id=([0-9]+)$
RewriteRule ^/bmw\.php$ http://www.example.com/bmw-%1-%2 [R=301,L]
It is not necessary to create any directory or file corresponding to /bmw-32-12 -- There is no required one-to-one relationship between URLs and files.
Jim
so how to let it show just
[example.com...]
For example, you can use the static URL-path /bmw to point to /bmw.php with no problem. But then, where will you get the values to populate the cat=32&id=12 query string? The static URL must contain all information needed to call the dynamic URL. It may be in a different form, but the information must be present.
If the above example doesn't do what you need to do, then you'll need to make a complete 'map' of all static URLs and their corresponding dynamic URLs, and make sure that the relationship betwen static and dynamic URLs is unique and unambiguous:
/bmw-sedan-blue -> /bmw.php?cat=32&id=12
/bmw-sedan-red --> /bmw.php?cat=32&id=14
/bmw-cycle-blue -> /bmw.php?cat=33&id=12
/bmw-cycle-red --> /bmw.php?cat=33&id=14
etc. You can then use RewriteMap to do the translation in httpd.conf or, worst-case, build a list of individual RewriteRules, one for each fixed static-dynamic realtionship, i.e. sedan=cat32, cycle=cat33, blue=id12, red=id14. Obviously, the more organized the relationship is, the fewer rules will be needed.
Another alternative is to do the parameter translation (e.g. red->id=14) at the php level, since you'll have database access to help you.
Jim