URL syntax

25 views
Skip to first unread message

The Sage Colleges Webmaster

unread,
Apr 12, 2012, 2:48:57 PM4/12/12
to Reason Discussion
I'm going through some information and am working on some SEO
techniques and one that I've come accross quite a few times is the
syntax that you should use hypens (-) in your urls instead of
underscores (_). In trying to create a URL in Reason that has a hyphen
in it, it does not allow for that character. Is there a way to:

1) Change the allowed syntax for the URL of a page to allow hyphens?
2) Change all current pages that have underscores to hyphens?
(automatically, as I suppose I could go into the page and edit the
page and change from underscore to hyphen).

Thanks.

- Kevin Haneslman
Director of Web Strategies
The Sage Colleges

Nathan White

unread,
Apr 12, 2012, 5:24:13 PM4/12/12
to reason-d...@googlegroups.com
Hi Kevin - the code that checks the URLs when you create pages is in the file reason_package/reason_4.0/lib/core/content_managers/minisite_page.php3 in the method run_error_checks(). In my development version of Reason it is line 348:

if( !preg_match( "|^[0-9a-z_]*$|i" , $this->get_value('url_fragment') ) )

I think if you change that to this it will work:

if( !preg_match( "|^[0-9a-z_-]*$|i" , $this->get_value('url_fragment') ) )

I would probably see how many you have before you try to change them automatically. If it is just a handful, it probably is easiest to change them manually. That way, the URL History and RewriteRule updates are taken care of for you.

Something like this should find them:

$es = new entity_selector();
$es->add_type(id_of('minisite_page'));
$es->add_relation('page_node.url_fragment LIKE %-%');
$result = $es->run_one();

A script to automatically update them would want to do these things:
  1. reason_update_entity to change the value of url_fragment to replace _ with -
  2. update_URL_history using the page entity id
  3. create a url_manager object for each site where page urls changed and run rewrites
    1. $um = new url_manager($site_id)
    2. $um->update_rewrites();
You can look at the finish() method of minisite_page.php3 to see how these operations are typically run when a page URL changes.

Hope this helps!

Nate

The Sage Colleges

--
You received this message because you are subscribed to the Google Groups "Reason Discussion" group.
To post to this group, send email to reason-d...@googlegroups.com.
To unsubscribe from this group, send email to reason-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/reason-discussion?hl=en.


The Sage Colleges Webmaster

unread,
Apr 16, 2012, 9:36:32 AM4/16/12
to Reason Discussion
Thanks Nate.
I found the line in minisite_page.php3 and changed that.. (btw, I had
to escape the hyphen so "0-9a-z_\-")... Now I'm trying to figure out
how to change the validation script that runs that checks to see if
the user actually put correct information in the URL fragment input
box. As it currently stands the page will allow me to save it with the
hyphen in the url fragment but when I type the hyphen it adds the
class "rules inappropriate_url_warning". I found that class addition
in the /js/content_managers/page_parent_url.js file - but don't see
where it has a regex to test against.

- Kevin

On Apr 12, 5:24 pm, Nathan White <n...@natewhite.com> wrote:
> Hi Kevin - the code that checks the URLs when you create pages is in the
> file reason_package/reason_4.0/lib/core/content_managers/minisite_page.php3
> in the method run_error_checks(). In my development version of Reason it is
> line 348:
>
> if( !preg_match( "|^[0-9a-z_]*$|i" , $this->get_value('url_fragment') ) )
>
> I think if you change that to this it will work:
>
> if( !preg_match( "|^[0-9a-z_-]*$|i" , $this->get_value('url_fragment') ) )
>
> I would probably see how many you have before you try to change them
> automatically. If it is just a handful, it probably is easiest to change
> them manually. That way, the URL History and RewriteRule updates are taken
> care of for you.
>
> Something like this should find them:
>
> $es = new entity_selector();
> $es->add_type(id_of('minisite_page'));
> $es->add_relation('page_node.url_fragment LIKE %-%');
> $result = $es->run_one();
>
> A script to automatically update them would want to do these things:
>
>    1. reason_update_entity to change the value of url_fragment to replace _
>    with -
>    2. update_URL_history using the page entity id
>    3. create a url_manager object for each site where page urls changed and
>    run rewrites
>       1. $um = new url_manager($site_id)
>       2. $um->update_rewrites();

Nathan White

unread,
Apr 16, 2012, 4:40:42 PM4/16/12
to reason-d...@googlegroups.com
Hi Kevin - it is on line 46 of page_parent_url.js - the existing javascript regexp basically looks for a non word character. We can replace it with something that instead makes sure it only includes the characters we allow:

var invalid = (!(/^[0-9a-z_\-]*$/i).test(value)) || (/\.html?$/.test(value));

I think that should do it.

Nate

The Sage Colleges Webmaster

unread,
Aug 16, 2012, 2:09:40 PM8/16/12
to reason-d...@googlegroups.com
Nate,
In addition to being able to do this for pages, I just ran into an issue where I was trying to do this for a new site and the add site module won't let me put the hyphen in either, it's requiring an underscore. Where would I change this for the Add Site module?

- Kevin

Nathan White

unread,
Aug 16, 2012, 2:47:19 PM8/16/12
to reason-d...@googlegroups.com
You need to change the regular expression used is in the run_error_checks() method of the site content manager. The file is here:

/reason_package/reason_4.0/lib/core/content_managers/site.php3

If you create an issue at github I'll change it in the core so that the 4.3 release of Reason in December has this fixed:

https://github.com/carleton/reason_package/issues

Nate

--
You received this message because you are subscribed to the Google Groups "Reason Discussion" group.
To view this discussion on the web visit https://groups.google.com/d/msg/reason-discussion/-/b7Ao1TDL5qEJ.
Reply all
Reply to author
Forward
0 new messages