Forum Moderators: phranque
which brings me to the url:
index.php?ArtId=1
I believe this could easily be changed to use a url like:
article1
by changing the .htaccess file to something like:
RewriteEngine on
RewriteRule ^article([0-9]+)$ index.php?ArtId=$1
However I have already created fields called "ArtURL" and would like to use these as the url so that I can choose the url when I submit the article. From here I am lost. I tried typing in:
index.php?ArtURL=dogs (dogs being the url in my database for the article)
and I was just brought back to my main page. I guess I don't exactly know how dynamic pages work, but if possible I would like to know how to go about choosing my own url's and if I'm even on the right track.
- Danny
Actually, you may be looking at this backwards.
In order to achieve what you want, you need to first modify your php script. You have two choices: You can either retrieve a different database variable for use as the static URL, or you can use preg_replace to modify the current dynamic URL that is retrieved from your database.
Either way you go, the static URL must either contain all information needed to reconstruct the dynamic URL, or you must provide logic in your script to look up the correct 'page' based not on articleID, but on the static URL -- and this implies that no two static URLs can be allowed to be the same.
The static URLs must also contain some kind of 'tag' to identify them as requests that should be passed to your script -- in other words, start or end the static URL with "/prod/" or "article-" or "widget" -- the 'tag' doesn't matter, as long as it uniquely identifies the URL as one that must be processed by your script.
Once your script has been modified to output static URLs, you then add mod_rewrite code to .htaccess or httpd.conf to detect these tagged URLs and pass them to your script. The script can them look up the required info to build the next page.
From a procedural viewpoint, it works like this:
There are many ways to do this, and the 'best' method depends on your script and database flexibility. Usually, the easiest method is to include the articleID in the static URL, as you have done in your example. This simplifies the scripting required and guarantees unique static URLs.
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim