CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    40

    website redirect

    I am trying to make a site that will use the extention off the URL to give a page a variable. For example, I want to follow the URL with a 10 digit number, and have that go to a page where the 10 digit number is a variable that the page can look at.

    For example, my site is www.mysite.com, and I ahve a page that loads different things based on a 10 digit variable. So i want the option for people to type in www.mysite.com/1234567890 (a 10 digit number) and the site will automatically load the page that uses that 10-digit number as a parameter for loading information.

    So right now the page that loads the information is www.mysite.com/classpage.php and I am wondering if there is an automatic way to have the www.mysite.com/1234567890 format to automatically just bring the user to classpage.php with a the 10 digit following number 1234567890 as some sort of variable for that page.

  2. #2
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    Re: website redirect

    You can use apache mod_rewrite to accomplish that. Put this ".htaccess" file on the root of you site:

    Code:
    # redirection for the MVC magic
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # if not file_exist
        RewriteCond %{REQUEST_FILENAME} !-f
        # and not dir_exist
        RewriteCond %{REQUEST_FILENAME} !-d
        # redirect to classpage.php + url
        RewriteRule ^/([0-9]+)$ classpage.php?number=$1 [QSA,L]
    </IfModule>

    This is an example of the classpage.php:
    Code:
    echo $_GET['number'];
    If my ^/([0-9]*)$ regular expression isn't wrong, that should match any url that ends with one or more number. You can modify the regular expression to better suit your needs.

    Good luck! Don't forget to mark thread as [resolved] if you solved it.
    All consequences are eternal in some way.

  3. #3
    Join Date
    Jun 2009
    Posts
    40

    Re: website redirect

    I'm not really familiar with that type of thing. Can you tell me what files like that are called (I see it says .c but it isn't c or c++) so i can look up how that whole thing is working, and maybe a tutorial where I could learn how pages like that work so I can better utilize it.

  4. #4
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    Talking Re: website redirect

    .htaccess files are used to configure apache on a per-directory basis. they are not in C or C++ syntax.
    Its about configuration, not programming. You can read more in: http://httpd.apache.org/docs/2.0/howto/htaccess.html

    Have a good day!
    All consequences are eternal in some way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured