I'm trying to rework a legacy site by converting .html to .php for ease of future configuration. To accomplish this I'm working within the Apache server on my Mac OS X 10.9 machine. I've written an users.conf file uses mod_rewrite to remap the file names ending in .html to run as .php.
It was working fine when I left work yesterday, but today I get a "You don't have permission to access" error on the front end and a "[error] [client ::1] client denied by server configuration:" on the back end when I try to access localhost/~user/somefile.html.php All of the file permissions are set correctly (644 or 755 as appropriate).
Seems to only happen with files named somefile.html.php. Files named .html load fine and files named .php load fine. Apache version is 2.2.24.
Here is user.conf:
<Directory "/Users/user/Sites/mySite">
Options Indexes MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Users/user/Sites/mySite">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*\.html) $1.php
</Directory>
And here is relevant part of httpd.conf:
DocumentRoot "/Users/user/Sites"
LoadModule php5_module libexec/apache2/libphp5.so
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/Users/user/Sites">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Maybe I've mixed together too many tutorials?
The answer was that I also needed to configure a virutal host.
This particular guide gave me the final clue I needed.
Related
I just have installed via homebrow apache, php, and Mysql on my mac, everything works fine.
But i tried to install phpMyAdmin, still from homebrew, i have edited my httpd.conf as mentionned.
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
but when i reach http://localhost/phpmyadmin it shows the code of index.php, which tells me that the alias is OK.
http://localhost/ with a phpinfo works fine. But the folder is in /Users/my-username/Sites/
I tried to put phpmyadmin in this folder but it launch a 404.
How to force a folder to process php with apache ?
I'm trying to make htaccess rewrite work on apache2 ubuntu 17.04 however it won't work. what i'm trying to do is access the route with localhost/anyroute but the only way to access it is localhost/PROJECTNAME/public/anyroute. localhost/ANYROUTE works on windows but apache will return "The requested url not found" on ubuntu and i have no idea why.. here are my confs file
.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
my vhost
<VirtualHost *:80>
DocumentRoot /var/www/html/test/public/
<Directory /var/www/html/test/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/test-error_log
CustomLog /var/log/apache2/test-access_log common
</VirtualHost>
apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
so bottom line is that localhost/anyroute won't work but localhost/project/public/anyroute will work. i have pretty much tried everything :/
Enabling mod_rewrite
Now, we need to activate mod_rewrite.
sudo a2enmod rewrite
This will activate the module or alert you that the module is already in effect. To put these changes into effect, restart Apache.
sudo service apache2 restart
We will need to set up and secure a few more settings before we can begin.
First, allow changes in the .htaccess file. Open the default Apache configuration file using nano or your favorite text editor.
sudo nano /etc/apache2/sites-enabled/000-default.conf
Inside that file, you will find the block on line 1. Inside of that block, add the following block:
/etc/apache2/sites-available/default
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Your file should now match the following. Make sure that all blocks are properly indented.
/etc/apache2/sites-available/default
<VirtualHost *:80>
<Directory /var/www/html>
. . .
</Directory>
. . .
</VirtualHost>
To put these changes into effect, restart Apache.
sudo service apache2 restart
Now, create the .htaccess file.
For Detail Follow Below Reference Link :
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
I'm trying to create a RESTful API on a VirtualHost on my Apache 2.4 server (on Ubuntu). I have a php file named dbManager.php which I am using a RewriteRule to look like an api directory. It's working great except for PUT and DELETE commands, which are returning 403 errors. Here's a redacted version of my conf file:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
<Limit PUT DELETE>
Require all granted
</Limit>
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Well, the PUT and DELETE still aren't working and returning 403. I'm also worried that I don't really want to allow PUT and DELETE everywhere on the directory, but only through the dummy api directory. What's the right way to do this?
I have managed to solve my question, but I don't really understand why it works:
<VirtualHost *>
ServerAdmin onigame#gmail.com
ServerName servername.com
ServerAlias *.servername.com
DirectoryIndex index.html index.php
DocumentRoot /path/to/local/dir/
<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory /path/to/local/dir/>
Require all granted
Satisfy All
</Directory>
# RESTful services provided for the fake "api" directory
RewriteEngine on
RewriteRule ^/api/(.*)$ /dbManager.php/$1 [L]
ServerSignature On
AddDefaultCharset utf-8
</VirtualHost>
Best I can figure out, getting a 403 means that it's access being blocked, and not the type of HTTP request (which would result in a 405, not a 403). And the access problem is on the local directory, so it needs a special section for it. But I really don't understand why the two lines I put there make things work. The Require directive, that sort of makes sense. But the Satisfy directive, from what I can tell from the documentation, should default to All.
And yet when I remove either line, it doesn't work.
I am using Vagrant to build up a little Wordpress development VM. When I select permalinks (postname) then the page from an article doesn't load. However, when I select the standard link (i.e page id) all is working good.
I've used the service PuPHPet to build the VM.
My settings can be found here
I am using Wordpress 3.9.1 and Apache2
I've enabled mod_rewrite be executing:
a2enmod rewrite
And my .htaccess file from Wordpress is as follows:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /svisa/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /svisa/index.php [L]
</IfModule>
# END WordPress
it has the following permissions and ownership:
-rw-rw-rw- 1 vagrant www-data 248 May 30 14:52 .htaccess
My virtualhost file for the site (/var/www/svisa/) can be found here.
from my host computer, I browse to the site via adress: http://wpdev-vm/svisa/
where wpdev-vm is the name of the vm.
Does anybody know what I am missing to make the permalinks work?
I solved the problem myself.
In the default apache configuration, under /etc/apache2/sites-enabled, where mine is called 15-default.conf
This was declared under the document root:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I had to change AllowOverride None to AllowOverride All. Thus you'll get the following:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
After that, the permalinks started working.
The (correct) answer above says that you need to change AllowOverride None to AllowOverride All in your xxx-default.conf file found in the /etc/apache2/sites-enabled directory.
However, in my vagrant box (precise64) none of the allowOverride or <Directory /var/www/>... code was present to begin with in the default.conf file.
I ended up having to add all of it between the VirtualHost tags, like below:
<VirtualHost *:80>
# Other stuff
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And then having to restart apache, like below, for it to work.
sudo service apache2 restart
I'm running Ubuntu 12.04 with Apache 2.2.22 and PHP 5.3.10. I'd like users to be able to request pages on my site without having to type the '.php' extension, and without having to worry about case sensitivity. For example, URLs like these...
http://www.site.com/test/phpinfo
http://www.site.com/test/PhPiNfO
...should both lead to:
http://www.site.com/test/phpinfo.php
I started with case insensitivity by following the accepted answer in this question. Here's what my '/etc/apache2/sites-available/default' file looks like...
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
RewriteMap lc int:tolower
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /var/www/test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
...and here's my .htaccess file:
RewriteEngine On
RewriteRule ^([a-z]+)/([a-z\-]+)$ /${lc:$1}/${lc:$2}.php [L,NC]
The file extension part is working, but for some reason case sensitivity is still being enforced. My Apache error log is filled with lines like this:
[Sat Jan 05 23:10:41 2013] [error] [client 192.168.1.9] File does not exist: /var/www/test/phpinfO
Any ideas what I'm doing wrong here?
EDIT: After experimenting for a couple hours, I'm seeing the most bizarre behavior! I thought maybe my .htaccess file was simply being ignored, so I filled it with gibberish. This produced an internal server error as expected. I then tried just these two lines in my .htaccess file...
RewriteEngine On
RewriteRule ^/(.*)$ /${lc:$1}
...and tried to access test/phpinfO.php unsuccessfully. I then deleted the .htaccess file and put those two lines directly into my '/etc/apache2/sites-available/default' file and restarted Apache. For some inexplicable reason, the behavior I wanted is now working! I can't possibly fathom how, since my only rule doesn't append '.php' to the URL!
This may sound odd, but it almost feels like my changes are taking effect in some delayed way. I tried some other tests that didn't work right away, but that seemed to work later when they shouldn't have. I keep testing and expecting my current setup to break without changing anything. Whatever the case, I am absolutely baffled.
Hope somebody can shed some f'ing light on this before I rip my brain out and smash it with a sledge hammer.
I finally figured this one out. Well, at least part of it. It turns out that the 'MultiViews' option was responsible for resolving files without the '.php' extension. That, in combination with these two lines in my '/etc/apache2/sites-available/default' file, gives me the behavior I desire:
RewriteEngine On
RewriteRule ^/(.*)$ /${lc:$1}
Unfortunately, I haven't been able to determine why my .htaccess file is ignored when it has the above rules, but not ignored when it has gibberish.
EDIT: OK, I figured out why the .htaccess file wasn't working. It was being read, but the second rule wasn't being matched. Here's why, according to the Apache documentation:
The removed prefix always ends with a slash, meaning the matching
occurs against a string which never has a leading slash. Therefore, a
Pattern with ^/ never matches in per-directory context.
As a result, I changed my .htaccess file to have this...
RewriteEngine On
RewriteRule ^(.*)$ ${lc:$1}
...and it's finally working!
CheckSpelling on
Matches files and directories. See the documentation for details.
Copied from = Case Insensitive URLs with mod_rewrite