RobA Wrote:I just noticed (realized) that child/parent relationships are not "enforced" when using pretty URLs.
...
Does anyone have any suggestion on how to enforce the URL structure and make only the first work?
-Rob A>
1. Change the RewriteRule in your .htaccess file to allow only one and two levels, something like:
Code:
RewriteRule ^([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ index.php?id=$2&parent=$1 [QSA,L]
(Not sure about the order or the flags, you'll have to try or read the apache doc)
2. Write a plugin, which tests the
parent parameter in the hook
index-pretemplate and shows
404 Page not found, if it is incorrect.
3. Submit the plugin to Extend ;-)
RobA Wrote:Does anyone have any suggestion on how to enforce the URL structure and make only the first work?
In gsconfig.php:
Code:
# Enable Canonical Redirects?
define('GSCANONICAL', 1);
But it won't work well with some plugins (e.g. those using url parameters)
Carlos Wrote:But it won't work well with some plugins (e.g. those using url parameters)
Thanks Carlos. That's too bad.
-Rob A>
RobA Wrote:Carlos Wrote:But it won't work well with some plugins (e.g. those using url parameters)
Thanks Carlos. That's too bad.
Well... it's can be useful for some sites...
A workaround could be: a plugin that works like GS's canonical redirect, but lets you exclude pages (like your Simplecache plugin). But it's not a complete solution -- those excluded pages would still be accesible with different url's.
Roba: you could try with grabbing whole url, explode it into array, and leave only domain + last 2 array elements.
Simplified solution: more than 3 (don't remember how
http://www.domain.tld/ is being split) elements -> redirect to 404.
A bit advanced is to redirect the user after merging array elements, looking if the target page physically exist, and then serve the page.
I've been doing something similar, to see if the page stays in a fixed location (domain/location/page.ext instead of /location/location2/location3/page.ext) and serve a dedicated content. The problem is that it would have to be scallable if you'd like to share your code. Let's not forget about plugins and their content, as array will contain also php variables.
Seems not that good idea as I firstly thought.
@RobA
A quick hack to make SimpleCache plugin enforce canonical URLs. Edit simplecache.php, line 48, insert this:
Code:
if ($_SERVER['REQUEST_URI'] != find_url(return_page_slug(), get_parent(false), 'relative')) {
redirect(find_url(return_page_slug(), get_parent(false)));
}
(Just after the
if(!in_array(return_page_slug() ... line)
You will be redirected to the
correct URL (structure defined in GS settings). Pages excluded from caching will not be checked/redirected.
Why choosing SimpleCache for this experiment? Because it has more or less the same
problem with url parameters as canonical redirection.
PS I might have tried to do a mini-plugin that reads SimpleCache's config and does all this, instead of patching the plugin, but there's a problem: as it would have to be hooked to 'index-pretemplate', I'm not sure if it would always (or on any system) be fired before SimpleCache (or any other plugin that uses that hook).