« Previous Next »

Answered Thread: dynamic subdomains and extensionless url's - feedback needed!

Last post 09-12-2007 3:22 AM by slov. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 07-06-2007, 6:05 AM

    dynamic subdomains and extensionless url's - feedback needed!

    I need feedback if my approach on the following situation is correct:

    I want my site to have dynamic subdomains with extensionless urls.
    So, a user may type "name.mydomain.com/language/page" e.g. "peter.mysite.com/en/blogs"
    (the name part in the url may be the name of a group or the name of a user)

    So lets say we have a group named "myGroup" and a user named "peter"
    And there are 2 types of blogs: groupblogs (displayed on the groupblogs.aspx) and userblogs (displayed on the userblogs.aspx)

    Valid urls would be:
    "peter.mysite.com/en/blogs"
    "myGroup.mysite.com/en/blogs"
    but they should be directed to different targetpages.

    My approach (please fill in the gaps if any):

    request is sent to IIS: peter.mysite.com/en/blog/2006/t=1

    ISAPI_rewrite always redirects to index.aspx
    ISAPI_rewrite rewrites to: http://www.mysite.com/index.aspx?name=peter&lang=en&page=blog&year=2006&t=1

    in index.aspx I then do the following (QUESTION: does the url the user sees remain friendly ("name.mydomain.com/language/page") after this action?)

    dim name as string=request.querystring("name")
    dim page as string=request.querystring("page")
    dim t as string=request.querystring("t")
    dim lang as string=request.querystring("lang")
    dim year as string=request.querystring("year")

    if page="blog" then
        if t="1" then
            server.transfer("www.mysite.com/userblogs.aspx?name="+name+"&lang="lang+"&t="+t+"&year="+year)
        else
            server.transfer("www.mysite.com/groupblogs.aspx?name="+name+"&lang="lang+"&t="+t+"&year="+year)
        end if
    end if

    Is this approach the adviced and correct one?
  • 07-09-2007, 11:16 AM In reply to

    Answered Re: dynamic subdomains and extensionless url's - feedback needed!

    Whenever someone wants to do an extensionless URL I always have to ask why?  Is there a technical reason?  Or do you just want the "look" of another system?

    The best way to use extensionless URLs is to work on a Unix-based system, such as Apache/Linux.  The Unix-style file system is designed not to pay attention to extensions, and in fact they aren't normally used for general files.  The Windows file system is based on using extensions to idnetify the file handler.

    Your way might work, but it's a lot of processing if this is just cosmetic.  And your URL showing in the address bar will change to what the rewritten URL is unless you enclose it in a frame or other such trick.

    Jeff

    Look for Wrox's new book Professional IIS 7 in your local bookstore, or order now at Amazon.com
  • 09-12-2007, 3:22 AM In reply to

    • slov
    • Top 500 Contributor
    • Joined on 09-11-2006, 5:36 AM
    • Posts 18

    Re: dynamic subdomains and extensionless url's - feedback needed!

    What you ask is possible with ISAPI_Rewrite 3.0 http://www.helicontech.com/isapi_rewrite/ without having need to script something in ASP. I suggest you to identify "type" of request by appending "group" word to the end of subdomain name instead of ugly "t=1". So the URL will look like:
    "peter.mysite.com/en/blogs"
    "SomeNameGroup.mysite.com/en/blogs"
    Also it is unclear where page parameter should go to.

    Here is a rules for ISAPI_Rewrite 3.0 syntax:

    RewriteBase /

    RewriteCond %{HTTP:Host} (?!www\.)([^.]+)group\.mysite\.com [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ([^/?]+)(?:/([^/?]+))?(?:/([^/?]+))?/? groupblogs.aspx?name=%1&lang=$1&t=2(?&year=$3) [NC,L]

    RewriteCond %{HTTP:Host} (?!www\.)([^.]+)\.mysite\.com [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ([^/?]+)(?:/([^/?]+))?(?:/([^/?]+))?/? userblogs.aspx?name=%1&lang=$1&t=1(?&year=$3) [NC,L]

    2Jeff: In fact this was a simple search engine friendly URLs question and not extension removal issue. But for those who interested, here is an example how to remove specific (for instance .asp) file extensions form request using ISAPI_Rewrite 3.0 features:

    #Redirect extension requests to avoid duplicate content
    RewriteRule ([^?]+)\.asp $1 [NC,R=301]

    #Internally add extensions to request
    RewriteCond %{REQUEST_FILENAME}.asp -f
    RewriteRule (.*) $1.asp


    PS: Seems like this forum only operational with IE. Cannot find how to highlight links in Opera, all my links remain plain text :(

    With best regards,
    Yaroslav Govorunov,
    Helicon Tech Corporation
    http://www.helicontech.com
Page 1 of 1 (3 items)
Microsoft Communities