Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Change url appearance

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

Page: 1 2
Go to End
Author Topic: 4016 Views
  • stalxed
    Avatar
    Community Member
    4 Posts

    Change url appearance Link to this post

    Hello,

    I just learned about cms/framework silverstripe.
    Great cms, except few things. Here they are:

    1. No reaction for error 404. For example:
    http://www.silverstripe.org/help-and-support/
    http://www.silverstripe.org/help-and-support/4444
    http://www.silverstripe.org/help-and-support/44/

    Works! but.. should work just first page, others should cause error 404 How I ca do it?

    2. I would like to add .html extension for pages, its very importnant for me.
    For exmaple:
    http://www.silverstripe.org/help-and-support.html
    And all other pages:
    http://www.silverstripe.org/help-and-support/
    http://www.silverstripe.org/help-and-support/4444
    http://www.silverstripe.org/help-and-support/44/
    Should cause error 404

    Please advice about this. Thank you very much for your support in this matter.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Change url appearance Link to this post

    URLs with an extension aren't supported, because SS relies on URL rewriting from the web server to operate.

    Why are extensions with .html important? I don't really see the need for these anymore. The web has moved on since the static HTML days.

  • stalxed
    Avatar
    Community Member
    4 Posts

    Re: Change url appearance Link to this post

    I am from Russia.

    In Russian internet very popular search engine http://yandex.ru(more popular than google.com).
    And search engine yandex very like site with extension .html.
       
    I do not see anything wrong in adding extensions. Html
    Good people ask you to help, tell me in what direction to edit the code system, to work extensions .html

    P.S. sorry for my bad english.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Change url appearance Link to this post

    There are URL rewrite options. On my site if you add non-existant URL data at the end of the HURl you get a 404.

    Check this it may help
    http://doc.silverstripe.org/doku.php?id=director&s=url%20rewrite

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Change url appearance Link to this post

    Here's a rewrite rule, that will force .html endings for all pages except the core (SilverStripe) URLs:

    ### SILVERSTRIPE START ###
    <Files *.ss>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    </Files>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)

    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{REQUEST_FILENAME} !-f
    # match home
    RewriteRule ^/?$ sapphire/main.php?url=/&%{QUERY_STRING} [L]
    # match predefined silverstripe urls
    # the following rule must be written on one line,
    # like this: ...processes)(?:/.+)?)$ sapphire/...

    RewriteRule ^((?:admin|dev|db|Security|images|api|soap|PageComment|processes)(?:/.+)?)$ sapphire/main.php?url=$1&%{QUERY_STRING} [L]
    # everything else must end with .html
    RewriteRule ^(.*)\.html$ sapphire/main.php?url=$1&%{QUERY_STRING} [L]
    </IfModule>
    ### SILVERSTRIPE END ###

    Your "help-and-support" page will then be accessible through http://yoursite.com/help-and-support.html
    But: This solution doesn't provide automatic output of .html endings when code is being generated. You could simply override the SiteTree Link method in your Page class. Something like this should do:

    public function Link($action = null) {
       if($action == 'index') {
          $action = '';
       }
       if($this->URLSegment == 'home' && !$action) return Director::baseURL();
       else return Director::baseURL() . $this->URLSegment . (!$action ? '.html' : "/$action.html");
    }

    This will actually create links with .html ending in your templates and works for most cases. It doesn't work when links are being inserted directly in the content area via CMS, also link backtracking will be broken (eg. changing a URL of a page won't automatically update all links to that page). For that to work, you must implement your own link backtracking and rewriting. Have a look at the SiteTree::onBeforeWrite method to get a clue how this could be done...

  • stalxed
    Avatar
    Community Member
    4 Posts

    Re: Change url appearance Link to this post

    Thank you very much!

  • Jesse B.
    Avatar
    Community Member
    2 Posts

    Re: Change url appearance Link to this post

    In my case, I work for a company that has spent a great deal of time and money on SEO, and has static pages currently. They would be unwilling to lose their inbound links due to changing urls on specific pages. The only way they will let me move the site to SilverStripe or any CMS is if the urls can be EXACTLY the same as they currently are. Other CMS (drupal for example) allow this, but I would rather use silverstripe.

    Some of the solutions provided in this thread offer a uniform solution, i.e. all pages will be reformatted in the same way, however, to complicate things the legacy naming is inconsistent. Some pages end in .html, some in .htm. some uses dashes between words and others use underscores.

    I really need to be able to specify an exact url on every page without it being overwritten by any naming convention, in order to satisfy my client's requirement of maintaining the current naming scheme. Has anyone worked out a way to do this? basically I would want to "turn off" all naming convention and have the url be exactly what I type.

    Sean, it would be a mistake to think that any convention satisfies all use cases, even if it is a better convention. sometimes we have to work within the confines of legacy sites and client whims.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Change url appearance Link to this post

    The best option though more involved is to set up 301 redirects from the old pages to the new. This is what I did on my sites when transitioning form a static site to SilverStripe. This way you don't loose any link love

    The URL of Silverstripe is already SEO Optimized since the page title is the link by default (plus you can customize under the Meta tab). And in 2.4 you have hierarchical URLs. The URL Path vs Document seems to be a fairly debatable issue in terms of SEO, but what it comes down to is as long your URL contains the keywords it doesn't matter if its a path or a document.

    I tend to Modify the Title and Navigation Link as well as the Meta path on many of my pages. Especially on press release page since the full article title is sometimes too long.

    4016 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.