I have created a URL shortening application, similar to tinyurl.com and bit.ly. I have everything working, but now I need to determine the Apache mod_rewrite .htaccess script that will allow the following:
When a user follows a link to http://example.com/abcdefg
it will display that URL, but internally will actually go to http://example.com/somepage.php
where PHP will determine the "abcdefg" portion of the URL and search the database for the long URL that is associated with "abcdefg".
Note: I currently have several lines of code being used to determine what the extension (i.e. abcdefg) is. It may be a cleaner to grab the extension if I have the "internal" page be somepage.php?extension=abc
defg . Either way, it should display http://example.com/abcdefg
I also want to be able to go to http://example.com/
without any characters (i.e. no abcdefg) following the / and have it load the default index.php page. On this page I will have the form into which you enter your long URL for shortening.
Perhaps "internally" it may need to go to a different page for the form page, while displaying http://example.com/
. I'm not sure, as I've never done any .htaccess code before.
Can you please asssist me with the .htaccess lines of code will tell Apache to do these requests? Any 'Cliff Notes" that you can add with it will be greatly appreciated as a learning tool.