URL Rewriting not working with ZF and apache2 - php

This has got me baffled. I recently set up VM in a hurry to go travelling. I installed Ubuntu 12.04 and LAMP. The PHP version is 5.5 and Apache is 2.4. I have used this same configuration on my home machine and it works fine.
Anyhow, the problem is that I can only access actions on the index controller of my ZF application, e.g: domainname/, domainname/index/info. If I try any other controllers, e.g. domainname/test/view, I get the apache 404 error. (Note - NOTE the ZF Not Found error).
I imagine this is a problem with URL rewriting, but the .htaccess on my VM is the same as my home machine, and I can't see anything in the virtual host configuration that would cause this. Also, if it was simply an URL rewriting problem, I would have thought it would come in to play for ALL urls, including the index controller...
Here's my htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Ideas?
EDIT: Here's the virtual host config:
DocumentRoot /home/kim/www/vhost/public
ServerName koop
SetEnv APPLICATION_ENV "development"
<Directory /home/kim/www/vhost/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined

Ok, so I had to change AllowOverride to All. That means Apache2 will now process my .htaccess files.
Then I needed to enable mod rewrite, by sudo a2enmod rewrite, then restart apache, i.e. sudo service apache2 restart

Related

Symfony (3.4) app : cant redirect requests to /web dir via .htaccess

I've a website lets say website.fr ( on server : /web/website ) ;
I ve added a symfony blog app in /web/website/blog/.
I dont manage to access the blog via website.fr/blog/ (404 error)
There is a .htaccess file in /web/website/blog/ directory, and one in /web/website/blog/web directory.
I am used to deploy symfony apps 'alone' on a server, and make the domain point to the web dir of the app, and everything always works fine, but in this configuration, I cant get it to work.
I have tried to use the following .htaccess conf under /web/website/blog/ :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [QSA,L]
</IfModule>
And I did not edit the default one under /web/website/blog/web/
Im not sure what Im doing wrong, so any help would be appreciated !
For me I use .. nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
which is explained Here and restart Apache, but I do not know if I understand your problem
I couldn't get what I wanted, but here is the solution I implemented :
I created a .htaccess in /web/website dir, that rewrites all requests to /web/website/blog, with the root (/) excluded from this rewriting :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ blog/web/$1 [QSA,L]
</IfModule>
That's not the way I wanted to get my rewriting, but I have the result I expected ; note that it would not be a good solution for a website that would evolve with new modules, routes, folders...

Symfony 3 on Apache server // Postman POST request not working without app.php in url

I have a working Symfony 3 API on an Apache Server - more info here and here these are already resolved
I am now facing a routing problem I think, my postman POST methods working fine if use a URL like: https://example.com/app.php/mcPDF/ but when I try with URL: https://example.com/mcPDF/ it says 404 not found.
I tried several answers here, like changing the htaccess IfModule mod_rewrite.c> section and added various settings in 000-default.conf file like:
<Directory /var/www/html/pdf/web>
AllowOverride All
Order Allow,Deny
Allow from All
DirectoryIndex app.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
and every time I do changes I do:
- bin/console cache:clear --env=prod --no-warmup
- bin/console cache:warmup --env=prod
and I also did the sudo a2enmod rewrite and restarted the server many times
Please advise, let me know what info you need more
All my PROD servers use configuration below and they all work fine. Try to update yours accordingly to see what happens.
# $ nano /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
DocumentRoot /var/www/my_app/current/web
<Directory /var/www/my_app/current/web>
AllowOverride All
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/${APP_NAME}-error.log
CustomLog ${APACHE_LOG_DIR}/${APP_NAME}-access.log combined
</VirtualHost>
UPDATE: Stage dependent configurations are shown here in details. http://www.inanzzz.com/index.php/post/0ew3/deploying-a-symfony-applications-to-staging-and-production-servers-with-capistrano

.htaccess file not works in LAMP

This is my .htaccess file. I am used Codeigniter Framework for my project.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Where is my mistake here? But It Works in xampp.
You can't just move from one server to another and not make sure your prerequistes are there. These things are not on by default on most systems. You also have not given any specifics about your setup or even your document root.
So going off that it's an Ubuntu server and apache2, you need to do these things.
First thing you need to do if this is a new LAMP install is make sure rewrite is on.
Run this command to enable mod_rewrite.
sudo a2enmod rewrite
Then you need to make sure you allow .htaccess in your document root.
edit
/etc/apache2/sites-available/000-default.conf
In this file search for this
AllowOverride None
and change it to
AllowOverride All
Then restart apache2.
sudo service apache2 restart
EDIT: Based on your comment, you need to make your vhost look like this and then restart apache2.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Open your terminal
Run this following code:
sudo nano /etc/apache2/apache2.conf
go down and change:
AllowOverride All
look like:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Then restart apache2.
sudo service apache2 restart
and then .htaccess file is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Are you sure mod_rewrite module is loaded ? go to httpd.conf and search for -
LoadModule rewrite_module modules/mod_rewrite.so
and make sure theres no # [hash tag] before

running laravel on a different port

I'm using Bitnami MampStack on OS X 10.9. Because this is an inherited laptop, I had to set up Apache under MAMP to listen on port 8888. I tweaked it to listen on 8889 as well and added the following as a VirtualHost in my httpd.conf file:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
Require all granted
</Directory>
</VirtualHost>
I followed the example here (so all my source code matches his). The index blade works, but the edit, create, and delete blades return a 404.
As I was testing, I discovered that http://localhost:8889/create returned a 404, but http://localhost:8889/index.php/create returned the correct view. Also, browsing http://localhost:8888/codebright/public/create works as expected.
So...me being kinda new to Laravel and MVC frameworks in general, is there some way I can have this installing running properly on port 8889?
Your virtualhost is working as it should, you just have now to be sure your public/.htaccess file is in place:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This is the file that rewrites your urls removing the /index.php from them.
EDIT
Also, check if you have mod_rewrite installed and enabled, because your .htaccess uses it, in Ubuntu/Debian, to enable it, you have to execute:
sudo a2enmod rewrite
Figured it out, thanks to this. I was missing AllowOverride All in the <Directory> section. Updated httpd.conf:
<VirtualHost *:8889>
DocumentRoot "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public"
ServerName localhost
<Directory "/Applications/mampstack-5.4.26-0/apache2/htdocs/codebright/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I thought I might have been missing RewriteEngine On in the VirtualHost definition but it doesn't seem to have an effect on my problem.

How do I get mod_rewrite to work with EasyPHP?

My mod_rewrite fails to work. This is the mod_rewrite section:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
It works like a charm on Ubuntu and OS X, but fails on EasyPHP under Windows.
I have uncommented the following line in the apache configuration:
LoadModule rewrite_module modules/mod_rewrite.so
And I have set every single AllowOverride directive to All (it's just a local server so it's irrelevant as far as security goes). The vhost entry for the particular vhost I would like mod_rewrite to be on is as follows:
<VirtualHost 127.0.0.1>
DocumentRoot "E:/Dropbox/Websites/mysite/public"
ServerName myvhost.mysite
<Directory "E:/Dropbox/Websites/mysite/public">
Options FollowSymLinks Indexes
RewriteEngine On
AllowOverride All
Order allow,deny
Allow from all
#Deny from all
Require all granted
</Directory>
</VirtualHost>
If I put a "die" at the top of the index.php file in my public folder, it never happens, so apparently the mod rewrite never even tried to redirect it to index.php. All I get are 404s.
See this answer:
easyphp and .htaccess
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
Hope this helps :)

Categories