.htaccess not working on localhost with XAMPP

142,541

Solution 1

Just had a similar issue

Resolved it by checking in httpd.conf

     # 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"

It is worth bearing in mind I tried (from Mark's answer) the "put garbage in the .htaccess" which did give a server error - but even though it was being read, it wasn't being acted on due to no overrides allowed.

Solution 2

In conf/extra/httpd-vhosts.conf, add the line AllowOverride All for all the websites that you are having problem with

<VirtualHost example.site:80>
    # rest of the stuff
    <Directory "c:\Projects\example.site">
        Require all granted
         AllowOverride All <-----This line is required
    </Directory>
</VirtualHost>

Solution 3

Try

<IfModule mod_rewrite.so>
...
...
...
</IfModule>

instead of <IfModule mod_rewrite.c>

Solution 4

Without seeing your system it's hard to tell what's wrong but try the following (comment answer if these didn't work WITH log error messages)

[STOP your Apache server instance. Ensure it's not running!]

1) move apache server/install to a folder that has no long file names and spaces

2) check httpd.conf in install\conf folder and look for AccessFileName. If it's .htaccess change it to a file name windows accepts (e.g. conf.htaccess)

3) double-check that your htaccess file gets read: add some uninterpretable garbage to it and start server: you should get an Error 500. If you don't, file is not getting read, re-visit httpd.conf file (if that looks OK, check if this is the only file which defines htaccess and it's location and it does at one place -within the file- only; also check if both httpd.conf and htaccess files are accessible: not encrypted, file access rights are not limited, drive/path available -and no long folder path and file names-)
STOP Apache again, then go on:
4) If you have IIS too on your system, stop it (uninstall it too if you can) from services.msc

5) Add the following to the top of your valid htaccess file:
RewriteEngine On
RewriteLog "/path/logs/rewrite.log" #make sure path is there!
RewriteLogLevel 9

6) Empty your [apache]\logs folder (if you use another folder, then that one :)

7) Check the following entries are set and correct:
Action application/x-httpd-php "c:/your-php5-path/php-cgi.exe"
LoadModule php5_module "c:/your-php5-path/php5apache2.dll"
LoadModule rewrite_module modules/mod_rewrite.so
Avoid long path names and spaces in folder names for phpX install too!

8) START apache server

You can do all the steps above or go one-by-one, your call. But at the end of the day make sure you tried everything above!
If system still blows up and you can't fix it, copy&paste error message(s) from log folder for further assistance

Solution 5

I had a similar problem. But the problem was in the file name '.htaccess', because the Windows doesn't let the file's name begin with a ".", the solution was rename the file with a CMD command. "rename c:\xampp\htdocs\htaccess.txt .htaccess"

Share:
142,541

Related videos on Youtube

acre
Author by

acre

Updated on July 22, 2022

Comments

  • acre
    acre almost 2 years

    i m using XAMPP but i m not able to use .htaccess file at local host. i m trying so many times.. Online working good. but local host showing [The requested URL was not found on this server]

    My root folder is real

    localhost/acre/real/property_available.php
    localhost/acre/real/properties
    
    
    <IfModule mod_rewrite.c>
     RewriteEngine On
     RewriteBase /acre/real/
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^properties$ /property_available.php/$1 [NC,QSA]
    </IfModule>
    

    Please

    • Admin
      Admin about 11 years
      Is localhost a windows or another system? Using a virtual host on server or dedicated machine? Is httpd.conf OK on localhost too (ie all other cfg)? Any error log data recorded on localhost? Double-checked that path info is OK (/prop....php)?
    • anubhava
      anubhava about 11 years
      Have you enabled mod_rewrite and .htaccess? What is your DocumentRoot?
    • acre
      acre about 11 years
      real folder is my document root. yaa enabled mod_rewrite and remove #from con file
  • RGriffiths
    RGriffiths almost 9 years
    I am having this issue too but can't find am http.conf file anywhere. Should I definitely have one?
  • TimP
    TimP over 8 years
    I think you should as its created during a default install. Note it is httpd.conf
  • RGriffiths
    RGriffiths over 8 years
    Thanks - found it. Accessed through the Xampp control panel. I was looking c:/ ..... path etc.
  • mr_plum
    mr_plum over 8 years
    This solved my .htaccess problem in a virtual host. I didn't see this solution mentioned anywhere else. Thank you!
  • Precastic
    Precastic over 7 years
    You can also always create any file that starts with a period in windows by appending a period to the filename... So create the file as .htaccess. and windows will strip the appended period and you end up with .htaccess
  • muhammad tayyab
    muhammad tayyab over 3 years
    interestingly this solved my issue when I changed permalinks in wordpress having no .htaccess all I edited within httpd.conf file to get this worked for my localhost wordpress setup
  • Tiny Sonhh
    Tiny Sonhh about 3 years
    This is the only way resolved my rewrite rule issue. I've been struggling for a week just to fix this. You saved my day! Thank you a lot.
  • Ibrahim.H
    Ibrahim.H almost 3 years
    Usually after trying a garbage in the .htaccess to make sure it works, we start by checking IfModule is activated, then we add the simplest rule without any conditions (something like path/page to direct/url) to make sure apache is working, then you can add your conditions one by one.
  • Amila Senadheera
    Amila Senadheera over 2 years
    this worked for me. Thanks a lot!