We're using Mod_rewrite and pretty urls, which works great. The problem is, all the children pages are available anywhere. For instance I can get to page1.htm from http://domain/page1.htm, http://domain/correctparent/page1.htm, http://domain/anyotherparent/page1.htm.
How would I set it up so all pages need the correct parent specified? Is there an option so that you have to specify the parent on the actual URL (http://domainname/index.php?page=pagena ... parentname).
Thanks for any help!
[solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
-
- Forum Members
- Posts: 11
- Joined: Wed Jul 22, 2009 7:58 pm
[solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
Last edited by davidkirk451 on Wed Aug 05, 2009 4:35 pm, edited 1 time in total.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Mod_rewrite Pretty URLs and Child Content Available From Any Parent
This is not a problem or a bug in CMSMS... we've gone over this numerous times...We're using Mod_rewrite and pretty urls, which works great. The problem is, all the children pages are available anywhere. For instance I can get to page1.htm from http://domain/page1.htm, http://domain/correctparent/page1.htm, http://domain/anyotherparent/page1.htm.
a) Users don't memorize or try to invent urls (except me and a few hackers), they bookmark them.
b) Search engines don't guess urls, they follow them.
c) the canonical stuff that google and other search engines are supporting now solves any duplicated content issues created by supplying numerous links to the same content.
Therefore, no problems.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
-
- Forum Members
- Posts: 11
- Joined: Wed Jul 22, 2009 7:58 pm
[solved] Re: Mod_rewrite Pretty URLs and Child Content Available From Any Parent
That's all great, but it was still a requirement here. I now have it working on our site at http://www.c7dc.com/.
This will 301 redirect any page to the proper /parent/child URL (like http://www.c7dc.com/services/colocation.htm) URL, even if you enter it with the actual index.php?page=pagename. I also added a check for news articles, so it doesn't do the redirection on them.
Here is the UDT that I inserted in all templates on our site to make this work:
This will 301 redirect any page to the proper /parent/child URL (like http://www.c7dc.com/services/colocation.htm) URL, even if you enter it with the actual index.php?page=pagename. I also added a check for news articles, so it doesn't do the redirection on them.
Here is the UDT that I inserted in all templates on our site to make this work:
Code: Select all
// get current page
global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
if ($thisPage!="")
{
//get current page parent alias
$currentNode = & $manager->sureGetNodeByAlias($thisPage);
$parentNode = $currentNode->getParent();
if(isset($parentNode))
{
$content = $parentNode->getContent();
$parent_title = $content->MenuText();
$parent_alias=$content->Alias();
}
else
{
$content = $currentNode->getContent();
$parent_alias=$content->Alias();
$parent_title="";
}
//Make available to smarty
$smarty->assign('parent_title', $parent_title);
$smarty->assign('parent_alias', $parent_alias);
preg_match('/^\/(.*)\/(.*\.htm||\/)$/', $_SERVER["REQUEST_URI"], $matches);
$urlparent=$matches[1];
$urlpage=$matches[2];
if (!isset($urlpage))
{
preg_match('/\/(.*\.htm|\/)$|/', $_SERVER["REQUEST_URI"], $matches);
$urlpage=$matches[1];
}
if(strcasecmp($urlparent,$parent_alias)!=0 && !preg_match("/news\/\d*\/\d*/", $urlparent))
{
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.c7dc.com/".$parent_alias."/".$urlpage);
}
}
Last edited by davidkirk451 on Thu Aug 06, 2009 7:13 pm, edited 1 time in total.
Re: [solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
Nice looking site, but you may want to run it thru the validation before putting the valid html button on site...
http://validator.w3.org/check?uri=http% ... %3Bq%3D0.7
http://validator.w3.org/check?uri=http% ... %3Bq%3D0.7
-
- Forum Members
- Posts: 11
- Joined: Wed Jul 22, 2009 7:58 pm
Re: [solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
Thank you for bringing that to my attention.
Re: [solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
Hello,
does your UDT work for /any/depth/of/path/to/page.html or only for /badpath/page.html ?
Pierre M.
does your UDT work for /any/depth/of/path/to/page.html or only for /badpath/page.html ?
Pierre M.
-
- Forum Members
- Posts: 11
- Joined: Wed Jul 22, 2009 7:58 pm
Re: [solved] Mod_rewrite Pretty URLs and Child Content Available From Any Parent
Nope, just one parent->child level. I would think you could modify it to do by having it call itself and start with that child page, but you'd have to make sure it didn't get into an infinite loop.