Forum Moderators: phranque
What's the best way (and most se friendly) to display the dynmaic url give a statuc url is entered? Unfortunately there's no easy reg expression for either the dynmaic or static url's.
We're currently redirecting 404 error pages (the static url;s) to a php script that looks up and displays the correct page from the database. Unfortunately this method is also returning a 404 to the se's.
I think more information is really necessary, before anyone can actually attempt to answer your question. Without knowing your URL structure, what you have tried or are considering trying, and what exactly you mean by 'no easy regex' solution, there is no real way to comment.
Would you please, provide examplified instances of each, and any other information that might be helpful or necessary?
Justin
So an example of a couple of urls might be:
www.domain.com/module.php&modulename=calculator&page=1
www.domain.com/module.php&modulename=calculator&page=3
or
www.domain.com/othermodule.php&modulename=userpages&page=44
where they map respectively (via a database table) to:
bigcalculator
calculator-ohio
contact-us
when you visit contact-us, the 404 page which is really a php script looks up contact-us in the table and spits out the appropriate dynamic page.
I thought I had this whipped,but it's kicking out a 404 in the page headers when I do it that way. I'm trying to preserve my table functionality while still getting rid of the 404 problem. I've got some functionality built into the website that allows me to do the mapping that I'd really like to preserve. Otherwise I'm going to have to rework the guts of the cms (which I'm guesing I'm going to have to do anyway :) ).
It looks like...
You can change these:
www.domain.com/module.php&modulename=calculator&page=1
www.domain.com/othermodule.php&modulename=userpages&page=44
to these:
www.domain.com/modulename/calculator/1.html
www.domain.com/othermodule/userpages/44.html
and use this:
RewriteRule ^modulename/([a-z-]+)/([0-9]+)\.html$ /module.php&modulename=$1&page=$2 [NC,L]
RewriteRule ^othermodule/([a-z-]+)/([0-9]+)\.html$ /othermodule.php&modulename=$1&page=$2 [NC,L]
I will elaborate later, was... just checking in for a few minutes.
Maybe I am missing something?
Justin
BTW this ([a-z-]+) will catch letters or hyphens between / and / so it will qualify for calculator-ohio, etc.
Added: $ to end the left side rule... see what happens when I hurry?
The books suggests the use of a rewritemap to an external program -or
script- that requests your database and returns the response to Apache:
RewriteMap nice2hash ext:somescriptorprogram
RewriteCond %{ SCRIPT_FILENAME } !-f # for missing files
RewriteRule (.*) ${nice2hash :$1¦$1}
[httpd.apache.org...]
[httpd.apache.org...]
[httpd.apache.org...]
Just keep the 404 status away by _redirecting_ to that script:
rewritecond %{ SCRIPT_FILENAME } !-f
rewriterule .* /your404script.php [PT,L]
Just keep the 404 status away by _redirecting_ to that script:
I would be *very* careful about not ever serving a 404 error...
You run a couple of risks depending on how your script works:
1. duplicate content on what are served as real pages.
2. 1 page with 'ever changing' content based on a request string.
If someone requests a page that really does not exist how does the script respond? If it serves a 'site-map', 'directory' or any other 'standard' page... any broken links will result in duplicate content.
If requests or a portion of requests are passed in any way other than a regular, non-query string, URL, the page will appear to be the same, with changing or rotating content. EG If someone requests stuff/index.html, and that page uses a POST (or even GET) to get more information out of the script, the page will not change in the browser, but the content will, an ever changing page.
Hope it works out for you though.
Justin