I'm having difficulties trying to set the following up:

Currently, User shortens a URL via PHP script, and it outputs http://example.com/3701 where that redirects to the page they inputted, as it is stored in a SQL table.

I've purchased example.com and I'm trying to get Apache to listen on the wildcard *.example.com and for a .htaccess file to pick it up and forward to the URL in the database.

3701.example.com should go directly to the page, not redirect to example.com/3701 then to the page, if possible.

Can this be done, and if so, how?

Thanks! (Apologies with the grammar, I'm Chinese).

EDIT: Nevermind, I got it. Here's the .htaccess for future reference:

Make the DNS listen on *.example.com

RewriteCond %{HTTP_HOST} ^(.*).example.com
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/%1/$1 [L]
link|improve this question
3  
Hi Sean, glad you got your problem sorted out! Please post your answer as an "answer" and mark it as accepted once enough time has past. That will help future visitors. – Mark Henderson Jan 1 at 20:55
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.