View Full Version : .htaccess not working on localhost.
Any ideas why this could be? I'm using the same file on my remote host, and it works just fine there.
This is how the .htaccess file looks like
RewriteEngine on
RewriteRule ^showproperty/([0-9]+)(/)?$ /showproperty.php?p=$1
I've checked apache's httpd.conf file and it says
# 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
#
# AccessFileName: The name of the file to look for in each directory
# for access control information. See also the AllowOverride directive.
#
AccessFileName .htaccess
Any help is appreciated.
bizzar528
08-29-06, 08:54 AM
Is your localhost a windows or linux server?
Change:
AccessFileName .htaccess
To:
AccessFileName htaccess.txt
Save and restart apache, rename .htaccess to htaccess.txt and it should work.
If your using IIS, then they won't work at all since IIS doesn't use htaccess.
Hope this helps!
I'm using Apache on a Windows machine.
I tried your suggestion, but I'm still getting the server error.
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
I didn't mention before what kind of error I get, but it was the same than now.
The original settings you posted should work (they do for me - winxp pro, apache 2.0.59, php 5.0.5 running as an apache module.) Using AccessFileName .htaccess works on windows. The only problem with it is creating/renaming a file with that name.
I put your lines into my .htaccess file and I don't get your error when browsing to a generic .php file. (I did get a server not configured error... when the rewrite_module was not loaded.) Do you get this error for all .php files or just the showproperty one?
Since the error mentions cgi, is your PHP running under cgi or is it running as an apache module?
The directory where I place the .htaccess file in won't even show up. I get this error as soon as I type the directory name in the address bar, or as soon as I try to open a file in it.
Since the error mentions cgi, is your PHP running under cgi or is it running as an apache module?
It's running as Apache module if I'm not mistaken. How would I find out to be sure? I'm using XAMPP if that helps.
Hmm.. Since you get the error for any document in the folder, it seams like a module is not getting loaded or a configuration problem. Check the apache server logs.
I guess if there is a default document in the folder that is a .php file, PHP being cgi or a module could cause this, but this would require some additional problem with the configuration. If PHP is running under cgi there will be a line similar to this in the httpd.conf -
Action application/x-httpd-php "c:/php5/php-cgi.exe"If it is running as a module, there will be a line similar to this -
LoadModule php5_module "c:/php5/php5apache2.dll"
This is what httpd.conf says
#ScriptAlias /php/ "C:/SERVER/xampp/php/"
#Action application/x-httpd-php "/php/php-cgi.exe"
LoadModule php5_module "C:/SERVER/xampp/apache/bin/php5apache2.dll"
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .php5 .php4 .php3 .phtml
And this is what the error log says
[Tue Aug 29 18:41:01 2006] [alert] [client 127.0.0.1] C:/SERVER/xampp/htdocs/procoim_websites/peniscola-properties/.htaccess: Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration
I'm kinda lost... :confused:
Sounds like the rewrite module is not loaded. Check this line in the httpd.conf (should not be commented out with # at the start of the line) -
LoadModule rewrite_module modules/mod_rewrite.so
<--- three more posts to go to get to Code Master
Hm, I uncommented this line, restarted Apache, and the error is gone, but it doesn't seem to rewrite anything. When I go to ./showproperty/2204 I get a 404 Error. ./showproperty.php?p=2204 works though.
Do other types of commands work in the .htaccess? What I am getting at is - does .htaccess function at all or is it just the rewrite commands?
Edit: I created the following test file, and it works for both cases -
<?php
echo "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}";
// Show all information, defaults to INFO_ALL
phpinfo();
?> I am entering a full url - http://mylocalhostname/showproperty/2204 and this also worked - mylocalhostname/showproperty/2204. I don't understand the ./ usage you listed.
I tried something simple, such as
Redirect testfile.php http://www.google.com
And it doesn't seem to work either.
And while typing this does it seem like I found the problem. I removed the slash infront of showproperty in this line
RewriteRule ^showproperty/([0-9]+)(/)?$ /showproperty.php?p=$1
And it's working now. I guess the reason why it doesn't work with the slash is cause I have the files in a subfolder of htdocs?
As for the ./, I got used to put it infront of the filename if it's in the same directory. I don't know why. Shouldn't I do that?
Thanks for your help, Mab.
When I go to ./showproperty/2204 I get a 404 Error. ./showproperty.php?p=2204 works though.The ./ is correct for relative urls. I just don't understand the context where you are entering this. The testing I did was through entering the url in the browser address bar. This required me to at least include the localhostname/filename.
The change you made makes sense for why it worked on a remote server (you would be entering full urls) and not on the local server (using the shorthand/relative url.)
The ./ is correct for relative urls. I just don't understand the context where you are entering this. The testing I did was through entering the url in the browser address bar. This required me to at least include the localhostname/filename.
Now as you say, I don't know why I put it like that. I did the same as you did, entering the full URL in the address bar.
nadiralishah
12-07-07, 10:43 AM
i specially create this account here to say thanks to mab... i was having this LoadModule issue since a while.. i wasn't know that LoadModule is commented.. and my work was working perfect on the server but not on localhost because of LoadModule commented... Thanks mab for help.. i just reviwed your post and its a good addition in my programming knowledge.. Thanks again...!!!!
i think that help you posted to someone on some other thread..
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.