Use .htaccess file on an apache localhost server

64,285

Solution 1

.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

Solution 2

Enable .htaccess on apache servers in localhost

1) Find your apache directly which uses the php installation .
2) Open your httpd.conf  with notepad, Which is located in the path \apache\conf directory
3) Find the code like below       
      #LoadModule rewrite_module modules/mod_rewrite.so
4) Remove # from above code


# AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 #   Options FileInfo AuthConfig Limit
 #
 AllowOverride All   <--- make sure this is not set to "None"


5) Save httpd.conf file
6) Restart your apache server

Solution 3

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.

Solution 4

Try This.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projectfolder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /projectfolder/index.php [L]
</IfModule>
Share:
64,285
KFox
Author by

KFox

Updated on July 05, 2022

Comments

  • KFox
    KFox almost 2 years

    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

  • NewBee
    NewBee about 6 years
    Thanks. Just adding a small part to avoid Step 1 & 2 for WAMP users. Click on the WAMP icon, scroll to Apache. You will directly get the httpd.conf file to edit.
  • Nagaraj Pujar
    Nagaraj Pujar over 5 years
    confirm that you have enabled the rewrite_module on Apache server and also check your httpd.conf file to make sure that there is no "#" i.e. commented at the beginning of this line LoadModule rewrite_module modules/mod_rewrite.so