Click to See Complete Forum and Search --> : website redirect


hojoff79
September 16th, 2009, 02:47 AM
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.

bubu
September 16th, 2009, 09:39 PM
You can use apache mod_rewrite to accomplish that. Put this ".htaccess" file on the root of you site:

# 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:
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. :wave:

hojoff79
September 20th, 2009, 03:26 PM
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.

bubu
September 23rd, 2009, 06:54 PM
.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!