I'm working on a new server and I installed via yum the "Web Server" group. Php and mysql work fine but I can't get .htaccess to work.
Heres my test .htaccess file:
WASD_TEST_CALL_ERROR
I put this as .htaccess in a test folder along with an index.html page.
Instead of reporting an error it goes ahead and loads the index page without displaying any errors.
Thanks
Make sure AccessFileName set to .htaccess
Search httpd.conf for AccessFileName directive. It defines name of the distributed configuration file:
grep -i AccessFileName httpd.conf
Make sure users are allowed to use .htaccess file
What you can put in these files is determined by the AllowOverride directive. This directive specifies, in categories, what directives will be honored if they are found in a .htaccess file. If this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
grep -i AllowOverride httpd.conf
When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files:
AllowOverride All
Save and close the file. Restart httpd:
service httpd restart
Have you set AllowOverride in Apache config? If not, set AllowOverride from none to all.
On CentOS7, the following should help:
Under string AllowOverride controls what directives may be placed in .htaccess files in /etc/httpd/conf/httpd.conf:replace AllowOverride None to AllowOverride All
In /etc/httpd/conf.modules.d/00-base.conf check rewrite_module must be:
LoadModule rewrite_module modules/mod_rewrite.so
.htaccess file must be in /var/www/html/
Example content .htaccess:
AuthUserFile /var/www/.htpasswd
AuthGroupFile /dev/null
AuthName "Please Enter Password"
AuthType Basic
Require valid-user
check and restart Apache:
httpd -t
/bin/systemctl restart httpd.service
Go to /etc/httpd/conf/httpd.conf and find below line. htaccess Context is allowed in .htaccess files: AllowOverride All
Save and close the file. Restart httpd:
/etc/httpd/conf/httpd.conf:replace AllowOverride None to AllowOverride All
httpd -M | grep rewrite_module should result
rewrite_module (shared)
Still not working even after making sure all above in place? Then make sure your .htaccess has below line at the top.
RewriteEngine On
Related
I've just installed ubuntu-server_6.04.2_LTS, after the fresh installation I've enabled mod_rewrite, it's showing in phpinfo()
my .htaccess file is OK
but, still requests are not going through index.php
You should check if for that specific directory (root folder of your project), apache is configured to allow overriding through .htaccess.
If you want to allow such override, the directives found in apache.conf or the specific settings for your virtual host should look like this:
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
OK, I've been having some issues with aws or something, such that I cannot seem to get mod_rewrite to work.
Just for testing purposes I've done the following:
1 used aws console to deploy fresh ami 64 bit instance from wizard
2 yum installed apache
3 edited /etc/httpd/conf/httpd.conf:
so that
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
looks like
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
4 made sure that
LoadModule rewrite_module modules/mod_rewrite.so
is in the file and uncommented.
5 restarted apache:
sudo /sbin/service httpd restart
6 created two new files:
/var/www/html/test1.html
contains:
this is test1!
/var/www/html/test2.html
contains:
this is test2!
7 created file:
/var/www/html/.htaccess
contains (IN TOTAL):
RewriteEngine on
RewriteRule ^test1\.html$ test2.html [L]
8 went to:
http://[my aws server]/test1.html
Am getting "this is test1!"
I am doing something wrong here, but for the life of me I have no idea what. Any help is greatly appreciated...
EDIT: I added nonsense chars/numbers to the beginning of my .htaccess file, and restarted apache (not 100% sure that is needed, but what the hey...), and nothing happened. In other words, I expected that going to the url [aws server]/test1.html would result in some kind of error, but it did not. I suspect apache is not even reading the .htaccess file.
EDIT: I added the following to my httpd.conf file:
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
The file is created when I restart apache, but nothing ever goes in there when I go to either page I've set up. I'm failing to do something very, very basic here, but I'm not sure what...
Not sure if this is the cause of your problems, but you shouldn't mess with the
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
line, and it should be something like:
<Directory />
Options FollowSymLinks
AllowOverride None
Deny from all
</Directory>
You should add the directory of your document root as a different container:
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
Took me a while to find this but in some installs Apache will use multiple config files.
Look in "/etc/apache2/sites-enabled/000-default" and check that AllowOveride is set to All
Try it. This work for me.
The first, you need to make sure the .htaccess file put in correct directory.
For this, you go to sites-enabled folder and check which the .conf files are enabled.
cd /etc/apache2/sites-enabled
ls
Ex: 000-default.conf
Then, goto sites-available folder to edit that .conf file.
cd ../sites-available
sudo gedit 000-default.conf
Find to DocumentRoot and check directory again.
If you put .htaccess file in /var/www/html/.htaccess so this line look like this:
DocumentRoot /var/www/html/
The second, You need modify <Directory> block look like this.
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
#RedirectMatch ^/$ /apache2-default/
</Directory>
Finally, you save file and restart apache
service apache2 restart
Hope this help!
I need help with EasyPHP and .htaccess .
The .htaccess file isn't working, I think its because I didn't setup something with EasyPHP.
My EasyPHP version is 5.3.8.1
Maybe anyone knows how to fix this problem ?
.htaccess file :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^get/([^/]+) /func/get.php?link=$1 [NC]
Default installation of Apache in EasyPHP don't have activated the option to use .htaccess files to modify server configuration in folders.
You have to tell Apache what configuration can be changed with .htaccess files, and in which folder. To enable all config changes on main web server, you should edit http.conf (in Apache/conf folder), and look for:
<Directory "${path}/www">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# 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 None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
and change
AllowOverride None
to
AllowOverride All
To better fine tune it, read documentation about AllowOverride in:
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
Also, check that http.conf has mod_rewrite activated, look for:
#LoadModule rewrite_module modules/mod_rewrite.so
And remove the leading "#"
LoadModule rewrite_module modules/mod_rewrite.so
When working on a local website I fixed this problem by adding the website path (with the .htaccess) as a virtual host. Easyphp has got a module for this: 'Virtual Hosts Manager'. This wil automatically take care of the httpd.conf.
I searched in web for 2 days and I try to use htaccess in my local wamp but I can't! I know there is something wrong but I don't know where...
First: I activated "rewrite_module" in the apache menu, then I checked the phpinfo page and I saw that module added to its "Loaded Modules" part.
Second: I checked the httpd.conf and made some changes, it is the result (just important parts):
ServerRoot "c:/program Files/wamp/bin/apache/apache2.2.11"
Listen 80
ServerName localhost:80
DocumentRoot "c:/program Files/wamp/www/"
<Directory />
Options FollowSymLinks
# AllowOverride None
# Order deny,allow
# Deny from all
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
<Directory "c:/program Files/wamp/www/">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
Next: I made an alias to my workspace. Here is contents of its .conf file:
Alias /basic_test/ "e:/Projects/basic_test/"
<Directory "e:/Projects/basic_test/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
Next: I place a simple "index.php" and "test.php" in my workspace root and tested the alias by this addresses:
--> "localhost/basic_test/index.php"
--> "localhost/basic_test/test.php"
They worked perfectly...
Finally, I added a ".htaccess" file to the root of my workspace (beside index.php), and I wrote in it:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^index.php$ test.php
</IfModule>
But the problem occurred when I tried to test the ".htaccess" by this address:
--> "localhost/basic_test/index.php"
It shows an error page with this message:
Oops! This link appears to be broken.
Click on Wamp icon and open Apache/httpd.conf and search "#LoadModule rewrite_module modules/mod_rewrite.so". Remove # as below and save it
LoadModule rewrite_module modules/mod_rewrite.so
and restart all service.
RewriteEngine on
RewriteBase /basic_test/
RewriteRule ^index.php$ test.php
click: WAMP icon->Apache->Apache modules->chose rewrite_module
and do restart for all services.
Open the httpd.conf file and search for
"rewrite"
, then remove
"#"
at the starting of the line,so the line looks like.
LoadModule rewrite_module modules/mod_rewrite.so
then restart the wamp.
if it related to hosting site then ask to your hosting to enable url writing or if you want to enable it in local machine then check this youtube step by step tutorial related to enabling rewrite module in wamp apache
https://youtu.be/xIspOX9FuVU?t=1m43s
Wamp server icon -> Apache -> Apache Modules and check the rewrite module option
it should be checked
Note its very important that after enable rewrite module you should require to restart all services of wamp server
This is the opposite problem from most about which I have read. I am running Ubuntu 8.04 on an Amazon instance with Apache 2.2.8 and I can't figure out why setting AllowOverride to None for root doesn't stop my .htaccess file from being included.
I have a sub-directory with hello.py in it and an .htaccess file. When I browse to the file, it works fine with modpython serving the file. If I put some garbage in .htaccess I get a server error, so I know the .htaccess file is being used. Also if I delete the .htaccess file, hello.py is no longer server by modpython - instead the browser tries to open it.
In one of my sites-available (linked in sites-enabled), I have "AllowOverride None" for the root directory. I thought that this would prevent .htaccess from being included from root and all its sub-directories which should cause hello.py to not be served by mod_python. However, it continues to be served fine and I can test that .htaccess is still being included because when I modify it, I see the results in my browser.
Maybe there is something I am not understanding about my file in sites-enabled. This is the file I am using:
NameVirtualHost *:8080
<VirtualHost *:8080>
<Directory />
AllowOverride None
</Directory>
</VirtualHost>
Thanks for any help.
The reason the file is not served via mod_python when you delete .htaccess is because the setup for mod_python is located in it. If you move that stuff to your sites-available file, you can delete .htaccess, turn a blind eye to the problem, and call it a day.
If that doesn't satisfy you, then as to why .htacess is being read at all, I can't say. You are correct that AllowOverride None should prevent the file from ever being read. Have you considered the possibility that you screwed something up when adding the virtual site? Try throwing some garbage into the config and see if it complains, just to be sure it's being read at all.
AllowOverride is only allowed in <Directory>-sections, so you've done everything right.
One problem you could have is that other (sub-)<Directory>-sections set AllowOverride to something different than None. That will override the setting for these subdirectories.
I use
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
</Directory>
and in /var/www (my docroot) I can use .htaccesses.
The reason why mod_python does not work anymore if you delete your .htaccess is that mod_python setup is usually in .htaccess files.
If you need more information, please send us your configuration.
PS: In fact the docuementation linked above says that you should never set AllowOverride to something not None in <Directory />.