Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Alright, I got an Apache localhost server up and running with PHP and MySql. Now I want to be able to use a .htaccess file as well to use RewriteRule, But I'm at a loss where to put it.

I have these directories:

C:\dev\progs where Apache PHP and MySQL are stored, each in their own sub-directories, ie. C:\dev\progs\Apache and so on...

C:\dev\www where all the site files are stored.

I need to know where to put the .htaccess file, what configuration I need to do, and if what I'm my hopes and dreams are all for nothing.

Thanks

share|improve this question
I thought .htaccess config should not be used if you have access to the server config file, which in this case, you do. – DJDavid98 Jan 23 at 22:05
yeah, I heard something about that too, I just find the config file a little confusing. I can also find a lot more tutorials on .htaccess files. – KFox Jan 23 at 23:19

2 Answers

up vote 0 down vote accepted

.htaccess is a configuration file that should be stored where your page is. In short, it should be in c:\dev\www in Your case, but You should read this too. BTW don't forget to turn on mod_rewrite by deleting a hash from the line where it resides

LoadModule rewrite_module modules/mod_rewrite.so

and enable .htaccess by changing

AllowOverride None

to

AllowOverride All
share|improve this answer
Thank you. I had already done those configurations in the tutorial I used to set up the localhost. I'd vate for the answer if I could, but I'm pretty new, I only have 13 rep. Sorry. – KFox Jan 23 at 23:10

You place .htaccess file in the web directory you want the code to control (and any sub directories). For a Rewrite, it typically goes in the root dir and acts upon the index.php page.

For example, if you put the .htaccess file in \dev\www\ directory, and your .htaccess file has something like RewriteRule ^(.*)$ /index.php?/$1 [L] this is a regex that is saying get all the characters in the URL and append them to the /index.php? script. The /$1 is a back reference in regex.

share|improve this answer
Thanks for the mini tutorial on regex. All the others I looked at were super complicated, but that one really helped. – KFox Jan 23 at 23:13

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.