Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I need, but don't know how to make, an htaccess file that will send a user, when looking for the home page, to index.php. It should not send them anywhere when they look for a URL like /7fg4/.

Adfly, to the best of my knowledge, works like this: you make a link, it stores the shortened link. When the user tries to open the link the htaccess file sends them the contents of another file which reads the URL and proceeds accordingly. My website should work almost exactly as Adfly does.

Can anyone explain or write an htaccess file that would do this?

share|improve this question

migrated from stackoverflow.com Feb 18 '12 at 3:37

This question came from our site for professional and enthusiast programmers.

    
I suggest you read into the basics of URL rewriting. Or do you have any specific problem? –  lawl0r Feb 17 '12 at 22:50

1 Answer 1

You want to implement permanent redirects in .htaccess. To redirect the home page to default.php you need:

redirect permanent index.html http://example.com/default.php

index.html is the default document on most servers. To redirect the home page, you have to redirect the default document. In that rule, you would need to replace example.com with your own domain name.


Instead of redirecting the home page to default.php, I would recommend making that file your home page. To do so, you have to change the default document with a directive like this:

DirectoryIndex default.php

Then the contents of default.php will be served at the home page and users will never see default.php in the URL.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.