Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Migrating a Site to Silverstripe /

What you need to know when migrating your existing site to SilverStripe.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Preserving existing link structure


Reply


3 Posts   2713 Views

Avatar
chris_d

Community Member, 21 Posts

20 December 2008 at 4:12am

Hi there,
I've currently got a site with page such as domain.com/example.htm

I would like move the site into silverstripe, but keep the existing addresses.

For seo reasons, I dont want to just use mod_rewrite to rewrite addresses.

Ie I want to be able to go to domain.com/example.htm and load an actualy silverstripe page, then be able to link to domain.com/example.htm from other pages and menus.

So basically what Im asking is how can I get silverstripe to allow dots in filenames?
I've ripped out some of the code so it won't give me an error message when I try to use dots, but the dots are still being rewritten to dashes somewhere.

Thanks for any help,
Chris

Avatar
chris_d

Community Member, 21 Posts

20 December 2008 at 5:00am

Edited: 20/12/2008 6:13am

this was a bit of a bitch to get working so thought i'd post what i did to get this working in the end:

I used the nestedurls build and changed in SiteTree.php

      // Keep it clean
      } else if(isset($this->changed['URLSegment']) && $this->changed['URLSegment']) {
         $segment = ereg_replace('[^A-Za-z0-9]+','-',$this->URLSegment);

         $segment = ereg_replace('-+','-',$segment);

to

      // Keep it clean
      } else if(isset($this->changed['URLSegment']) && $this->changed['URLSegment']) {
         $segment = ereg_replace('[^A-Za-z0-9]+','-',$this->URLSegment);

         $segment = ereg_replace('-+','-',$segment);
//hack
$segment= str_replace("-htm",".htm", $segment);

also to get rid of trailing slashes:
   public function Link($action = null) {
$linkwithslash = Controller::join_links(Director::baseURL(), $this->RelativeLink($action));
if ('/' == substr($linkwithslash, strlen($linkwithslash)-1)) $linkwithslash = substr_replace($linkwithslash, '', strlen($linkwithslash)-1); // strip trailing slash

return $linkwithslash;   
//   return Controller::join_links(Director::baseURL(), $this->RelativeLink($action));
   }
   

Clearly there is a reason why the developers have chosen not to have this in by default (security?) so I'll have a look to see if I can tidy this up and post back later.
This trick could also be used to allow foreign letters in rusl etc.

Avatar
Bambii7

Community Member, 254 Posts

9 July 2009 at 5:01pm

Thats really cool, I'd prefer to append file names to URL's . It'd be interesting to find out if it is a security issue, it could just a usability issue.