Apache2: standart rewrite rule isn't working - php

Has a fresh setup of Apache 2.2 + PHP 5.3. Trying to run Yii site, which requires .htaccess file to be as following:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
But instead of running index.php file it lists the directory.
What I know:
.htaccess is being read and processed - if you break it, you get 500 IE.
mod_rewrite is On: LoadModule rewrite_module modules/mod_rewrite.so
PHP is up, I was able to run Adminer w/o any issues
Virtual Hosts file looks fine (see below)
httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "d:/denis/www/yii.local"
ServerName yii.local
ErrorLog "logs/yii.local-error.log"
CustomLog "logs/yii.local-access.log" common
# Other directives here
# DirectoryIndex index.php
<Directory "D:/denis/www/yii.local">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
#AccessFileName htaccess
</VirtualHost>
Update: If I add Options -Indexes to .htaccess I am getting 403 Forbidden, due to "Directory index forbidden by Options directive".

Related

setting .htaccess file in slim

I am having issues redirecting to index.php in my slim app with .htaccess file.
Routes work if I add the index.php at the end of the URL
So slimapp.dev/hello/myname gets error
Not Found The requested URL /hello/myname was not found on this server.
while slimapp.dev/index.php/hello/myname works
Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]
I am using Apache 2 on Ubuntu 18.04
File structure
public_html
|_index.php
|_ vendor
|_.htaccess
virtualHost 000-default.conf
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I use the php -S localhost:3000 it works as expected but if I use the Apache web server, I most add the index.php to the end of the URL to make it work. Thanks
You are doing wrong.This is quite simple with just two lines of code:
RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]

Symfony 3, domain name shows Directory Structure

I know this question is asked a lot but I read all the questions related to this but they didn't solve my problem.
I just deployed a Symfony 3 web app and I followed the Symfony server configuration documentation just to find out that the www.domain.com displays the directory structure!
Here's the configuration that I used of file /etc/apache2/sites-available/site.com.conf:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
I can see the app when I go to www.domain.com/web and www.domain.com/web/app.php
I want to be able to visit www.domain.com and see the app.
Change the line:
AllowOverride None
to next one:
AllowOverride All
Remove section <IfModule mod_rewrite.c> And use standard Symfony's .htaccess file.
Also you need to set up PHP as module for your apache. Be sure to have uncommented line in http.conf that loads PHP module:
LoadModule php7_module libexec/apache2/libphp7.so
You are missing your DirectoryIndex app.php or DirectoryIndex dev_app.php contained in your directory tag. This will cause apache to load app.php if a file has not been requested.
https://httpd.apache.org/docs/2.0/mod/mod_dir.html
<Directory /var/www/project/web>
DirectoryIndex app.php
...
</Directory>
Also make sure mod rewrite is enabled.
a2enmod rewrite
You may have to use sudo.
One final note:
Options -MultiViews should be contained inside the <Directory> for use all the time and not just when mod_rewrite is enabled.

Access forbidden Xampp Mac osx using yii2

I get the following error:
Access forbidden!
You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.
If you think this is a server error, please contact the webmaster.
Error 403
when I use the following code in my httpd-vhosts.conf:
<VirtualHost *:80>
ServerName frontend.dev
DocumentRoot "AmanAgarwal/Projects/basic/yii-application/frontend/web/"
<Directory "AmanAgarwal/Projects/basic/yii-application/frontend/web/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
## Apache 2.2
</Directory>
</VirtualHost>

CodeIgniter: Removing index.php from the URL

I was trying to remove the index.php from the URL, on my WAMP server THIS worked perfectly, but for some reason on my actual hosted server it's not.
I just created on my current Linux Ubuntu Server a sub-domain,
under /var/www/tools.example.com/public_html
I checked if mod_rewrite is enabled using a .php file I uploaded to the dir with this:
<?php
phpinfo();
and mod_rewrite is under "Loaded Modules".
so no worries here.
the .conf file I created in etc/apache2/sites-available/tools.example.com.conf looks like this:
<VirtualHost *:80>
ServerName tools.example.com
ServerAdmin walid#example.com
ErrorLog /var/www/tools.example.com/logs/error.log
CustomLog /var/www/tools.example.com/logs/access.log combined
DocumentRoot /var/www/tools.example.com/public_html
<Directory /var/www/tools.example.com.conf/public_html/>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
where AllowOverride All so using mod_rewrite with .htaccess is enabled.
I don't know why this is still not working. Any idea why?
the content of the .htaccess file in the main dir:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Edit #1:
I already went through all first 9 solutions in this post: CodeIgniter removing index.php from url
Your path is incorrect in your .conf file for the directory directive. Your document root listed should be the same as your Directory directive. So I don't think it's picking up the AllowOverride All directive.
Change this
<Directory /var/www/tools.example.com.conf/public_html/>
To this
<Directory /var/www/tools.example.com/public_html/>

mod_rewrite throws 404, however works on (almost) identical server

I have two VPS's of mine serve the same PHP application, however whitelabled to two different client's brands. The underlaying code is identical. I use a .htaccess to redirect all requests to index.php, and then use my MVC to render pages etc. This is my .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
It is the same on both servers. My Apache VirtualHost looks as follows:
<VirtualHost *:80>
ServerAdmin benedict#ovalbit.com
ServerName [REDACTED]
ServerAlias [REDACTED]
DocumentRoot /var/www/cloud/
DirectoryIndex index.php
LogLevel Error
ErrorLog /var/www/cloud/logs/error.log
CustomLog /var/www/cloud/logs/other.log Combined
<Directory /var/www/cloud/>
Options +ExecCGI
AllowOverride all
</Directory>
</VirtualHost>
Running a2enmod rewrite returns Module rewrite already enabled.
I am almost 100% positive that the file it is redirecting to it available, is there any way to log the result of mod_rewrite requests so I can be sure? Can anyone see any stupid errors I might have made?
I'm certain it's not due to the Apache config as I have another site on the same VPS which also uses a mod_rewrite and works fine.

Categories