Mono Support vanity urls 

Viewed 27731 time(s), 7 post(s), 5/17/2011 10:16:07 PM - by ldc0618
5/17/2011 10:16:07 PM
20 Reputation 5 Total posts

Is it possible to configure vanity urls for groups and users

for example:
http://localhost:8083/MonoX/Pages/SocialNetworking/Groups/GroupView/ogTE0Fmv1E6yrZ2lAYWbkg/Web-design/

would become:
http://localhost:8083/Web-design/

Thanks

1
5/18/2011 7:30:32 AM
15993 Reputation 2214 Total posts

Hi,

you may notice that (http://localhost:8083/MonoX/Pages/SocialNetworking/Groups/GroupView/ogTE0Fmv1E6yrZ2lAYWbkg/Web-design/) this is already a rewritten URL but if you want to make this even shorter you can do this by using the standard MonoX rewriting mechanism.  You can find more information related to MonoX URL rewriting in MonoX manual under the "2.5.1.1 URL rewriting". Here is a sample how this would look like:

<rewrite url="^(.*)/Web-design/(\?(.+))?$" to="$1/MonoX/Pages/SocialNetworking/Groups/GroupView/ogTE0Fmv1E6yrZ2lAYWbkg/Web-design/$2" name="WebDesign" defaultPage="/MonoX/Pages/SocialNetworking/Groups/GroupView/ogTE0Fmv1E6yrZ2lAYWbkg/Web-design/" urlPattern="/MonoX/Pages/SocialNetworking/Groups/GroupView/ogTE0Fmv1E6yrZ2lAYWbkg/Web-design/" />

Note: You need to add the above rewriting rule to the web.config

Regards

2
5/18/2011 1:43:38 PM
20 Reputation 5 Total posts

Thanks but what if i have ten of thousands of groups? I am considering migrating an existing community site to monox and this is a critical consideration for me. Is there a more generic rule or another approach?

3
5/18/2011 8:03:25 PM
7207 Reputation 956 Total posts

A more universal approach would require the presence of the groups' unique ID (a shortened Guid, like "ogTE0Fmv1E6yrZ2lAYWbkg" in the example above). MonoX by default does not require users to use unique group names when opening a group.
You can change this behaviour by changing the group-related URL rewriting rules, enforcing the name uniqueness in the group creation part (GroupEdit.ascx), and manually setting the GroupId property in the group view part (GroupView.ascx). This task requires a bit of coding, I we can send a code skeleton if you are interested.

4
5/18/2011 8:10:34 PM
20 Reputation 5 Total posts

That would be great if you could send as I am just getting started

5
5/20/2011 10:40:56 PM
7207 Reputation 956 Total posts

OK, I am preparing a small example that uses a simpler approach - using the custom URL rewriter transform method. It allows users to enter arbitrary URL formats that are transformed on the fly to the required set of parameters. In your case, group name will be transformed to the group id that is needed by all group modules, although that ID will not be visible in the URL.
Note that it is still recommended to have one additional level in your URL to identify the rewriting section. For example, instead of http://localhost:8083/Web-design/ you will need (in almost real world scenarios) to have http://localhost:8083/Group/Web-design/ . "Group" can be any string of your choice, but without it, basically every resource will be mapped to group section.



6
5/23/2011 8:07:58 PM
7207 Reputation 956 Total posts

As promised, I have put together a small blog post with a code sample that can be used in such scenarios: http://www.mono-software.com/Blog/post/Mono/110/Customizing-ASP-NET-URL-rewriting-rules/

7
This is a demo site for MonoX. Please visit Mono Software for more info.