Forum Moderators: phranque
I've got a project that relies on dynamic urls to serve the correct page (e.g. www.somesite.com/index.php?cmd=01.05.00).
Before I went "dynamic" a year or more ago, I knew that all you had to do to get a user to a 404 page was to put the following into the htaccess:
ErrorDocument 404 /.error/error.htm
BUT, when everyone of your URLS start with index.php followed by a query var, how does htaccess know when a page query is not valid?
I've currently set up a row in my db with custom error text code and I've tried to tweak my htaccess like so:
ErrorDocument 404 index.php?cmd=00.05.00
"00.05.00" is the query var for the 404 page, but this doesn't work.
Can someone please let me know how to make this work?
Great appreciation in advance!
Neophyte
Your script must handle *all* requests for such URLs, and generate the 404 response headers if no page can be generated for the requested query. It can then either generate the 404 error document contents, or "include" or "require" an external 404 error document file.
To help you avoid two common problems, remember that a 404 is not a redirect and that a query string is not part of a URL; A query string does not "locate" a resource on the Web, but rather is used *by* that located resource. So a query string is not part of a URL, but rather is data *attached* to a URL to be passed to the resource *at* that URL. Many Apache directives handle query strings separately from URLs, or do not handle them at all, so this latter point is more than just academic.
Backing off yet another step, be aware that most Webmasters are doing everything they can to avoid "dynamic URLs."
Also, it is considered best practice to avoid linking to "/index.xyz" and link to just "/". The advantages are usability (shortness, readability, memorability, ease of typing) and the independence of the URL on the Web site technology; There's no need to 'expose' the fact that you use PHP for example, and doing so means that your URLs might have to be changed if some better technology comes along later. Note that none of the "big sites" link to "/index.abc" or mention their technology in their URLs.
Jim
Appreciate very much your advice and insight.
be aware that most Webmasters are doing everything they can to avoid "dynamic URLs."
I've been considering using modRewrite to "re-format" my urls to the preferred www.somesite.com/some section/some page/ for quite some time now; I suppose now is the time to delve into this.
The PHP section of WebmasterWorld has a number of "library" posts containgin useful php-centric "best-practice-type" information... does the same hold true for the Apache Web Server section? Particularly in respect to different .htaccess issues?
Neophyte
Directly, it does no such thing.
What it does, is accept a URL request in the 'friendly' format, and internally 'translate' it to fetch content from an 'ugly' internal filepath.
To 'change' URLs you need to change the links on your pages to the new, 'friendly', format. It is these links that 'define' URLs.