26

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

neophyte
  • 6,540
  • 2
  • 28
  • 43
acre
  • 283
  • 2
  • 4
  • 6
  • 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)? –  Jun 18 '13 at 07:42
  • Have you enabled mod_rewrite and .htaccess? What is your DocumentRoot? – anubhava Jun 18 '13 at 08:40
  • real folder is my document root. yaa enabled mod_rewrite and remove #from con file – acre Jun 20 '13 at 08:22

9 Answers9

52

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.

TimP
  • 694
  • 5
  • 19
  • I am having this issue too but can't find am http.conf file anywhere. Should I definitely have one? – RGriffiths Sep 25 '15 at 12:34
  • I think you should as its created during a default install. Note it is httpd.conf – TimP Sep 28 '15 at 12:11
  • 1
    Thanks - found it. Accessed through the Xampp control panel. I was looking c:/ ..... path etc. – RGriffiths Sep 28 '15 at 23:23
  • 1
    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. – Ibrahim.H Jul 26 '21 at 18:12
34

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>
TheTechGuy
  • 16,560
  • 16
  • 115
  • 136
  • This solved my .htaccess problem in a virtual host. I didn't see this solution mentioned anywhere else. Thank you! – mr_plum Dec 19 '15 at 20:12
  • 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 – muhammad tayyab Oct 17 '20 at 07:05
  • 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. – Tiny Sonhh Jun 20 '21 at 13:42
13

Try

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

instead of <IfModule mod_rewrite.c>

Kristoffer Sall-Storgaard
  • 10,576
  • 5
  • 36
  • 46
user3114681
  • 131
  • 1
  • 2
6

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

4

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"

  • 6
    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` – Precastic Mar 26 '17 at 21:02
1

for xampp vm on MacOS capitan, high sierra, MacOS Mojave (10.12+), you can follow these

1. mount /opt/lampp
2. explore the folder
3. open terminal from the folder
4. cd to `htdocs`>yourapp (ex: techaz.co)
5. vim .htaccess
6. paste your .htaccess content (that is suggested on options-permalink.php)

enter image description here

TLbiz
  • 487
  • 8
  • 7
0

For windows user, make sure to closely look at this section.

RewriteRule ^properties$ /property_available.php/$1 [NC,QSA]

As said in Apache documentation :

The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly.

So ^properties$ means Apache will only look for URL that has exact match with properties. You might want to try this code.

RewriteRule properties /property_available.php/$1 [NC,QSA]

So Apache will see the URL that has properties and rewrite it to /property_available.php/

Haikal
  • 1
0

I've setup xampp for my localhost as well, I've not done anything with the files created by xampp during or after setup.

But in the '.htaccess' file, make sure you've set it to something like this. Works for me, and this should not make any difference for you.

RewriteEngine On
RewriteRule ^filename/?$ filename.html

Change .html to whatever format you're using.

Make sure your install is clean, and just make the .htaccess file. Also remember to put one .htaccess file for each directory (don't really know if you can use ONE file for all folders, but to be safe, just do this and it will always work.

-1

Edit the .htaccess file, so the first line reads 'Test.':

Test.

Set the default handler

DirectoryIndex index.php index.html index.htm

...

Ouma Nyang
  • 31
  • 5