szehau's weblog Life, Internet, Software, Gadgets, Programming and Investments

23Jul/0616

Enable .htaccess and url rewriting in Apache for Windows

ADVERTISEMENTS

When I try to setup PHP and Apache in my notebook, I try to enable the .htaccess setting in apache's httpd.conf. After I tried for a few hours (YES, a few hours) at my notebook and google-ing on the internet, finally I found the complete solution.

I record the steps here so that it can help those who want to enable .htaccess and url rewriting in Apache for Windows and also for my own reference in future.

1. Make sure you have setup apache and php correctly. Make sure that you can run php scripts without any problem.

2. Use notepad to open httpd.conf config file. Make use the line "LoadModule rewrite_module modules/mod_rewrite.so" is un-commented.

3. Under "<directory XXX></directory>" section, change the line "AllowOverride None" to "AllowOverride All".

4. Change the line "AccessFileName .htaccess" to "AccessFileName htaccess". This is because in Windows, we can't have a file with filename that starts with a dot.

5. Save the changed file and restart Apache Windows Service. You can then use the file htaccess to process your url rewritting.

Most Commented Posts

Comments (16) Trackbacks (1)
  1. nice howto, bookmarked :)

  2. Bravo! Worked like a charm. Thanks.

  3. Thank you for saving me those countless hours :)

  4. Brilliant! Thank you!!

  5. Thanks to szehau….
    :)

  6. you can create “.htaccess” file by using notepad(save as .htaccess file) in windows :)

  7. Thank you very much.
    the solution what u have given above is amazing.

  8. I try to follow steps that you showed on my laptop but it doesn’t work at all. You mentioned about
    4. Change the line “AccessFileName .htaccess” to “AccessFileName htaccess”.

    I am using wamp and don’t see anywhere in the httpd.conf file have that statement. Where should I put it in the httpd.conf?

    Thanks for your help

  9. Hi Vuong Ho, you can try put the line to the end of the httpd.conf file or any place in the httpd.conf file (but not between and tage).

  10. Hi,

    I couldnt find httpd.conf file in my server…can u help me can we write manually httpd.conf file…

    Thanks
    Developer

  11. Hi, you get a sample configuration from apache.. just download the full package from apache and use the httpd.conf in the package.

  12. The solution is given is amazing and solved my problem after a lot of search in the internet.Thanks

  13. Hi Sarwar Zahan, you are welcome.

  14. Worked for me too…

  15. Brilliant solution, but in order for the thing to work 100% you need to add

    Order allow,deny
    Deny from all
    Satisfy All

    into httpd.conf file.
    and change names of all the “.htaccess” to “htaccess” in all the directories on the website.

    thank you for pointing me out to right direction.

  16. Thank you too, Andrei.


Leave a comment