Apache mod_rewrite doesn't work - php

I want use mod_rewrite but seems that is not working, I activated it and I setup in my .htaccess but nothing seems to work.
I want to NOT display index.php in my URL :
instead of
localhost/index.php/admin/login
I want to display
localhost/admin/login
I am under Ubuntu
Here is what my phpinfo() says :
This is my .htaccess :
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
#RewriteBase /virtualpost
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:/virtualpost]
#RewriteBase /
RewriteCond %{HTTP_HOST} ^((?!localhost).)*$
RewriteRule . - [E=REWRITEBASE:/]
# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(system\/virtualpost\/cache|system\/codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is my /etc/apache2/sites-available/000-default.conf :
<VirtualHost *:80>
SetEnv MYSQL_DB_HOST localhost
SetEnv MYSQL_USER root
SetEnv MYSQL_PASSWORD spaces
SetEnv MYSQL_DB_NAME clevvermail
<Directory ...>
AllowOverride All
</Directory>
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>

I figured out that I had to config the apache2.conf file /etc/apache2/apache2.conf and change
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None <<-- Rewriting desactivated
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All <<--Activate rewriting
Require all granted
</Directory>

Related

How to run multiple instances of Laravel on the same domain?

I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.
Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instances production,staging and dev using the following links
serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev
I found another SO question which seems to be doing the same thing. But when I tried to do the same thing I get the following error
Forbidden
You don't have permission to access /dev on this server.
Here is what I have done so far. In my httpd-vhosts.conf file I added the following VirtualHost
<VirtualHost *:8080>
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
DocumentRoot "C:\www\dev\public"
ServerName serv1.example.com
ServerAlias /dev
<Directory "C:\www\dev">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Then I changed c:\www\dev\public\.htaccess the code to the following
<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>
What did I do wrong here? how can I access each instance using the same domain?
Try This one, in your Apache configure file /etc/apache2/sites-available
<VirtualHost *:8080>
ServerName serv1.example.com
ServerAlias serv1.example.com
DocumentRoot "C:/www/dev/public"
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "C:/www/dev/public">
Options All
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
# Log file locations
LogLevel warn
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
And in your c:\www\dev\public\.htaccess
<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]
I hope this would work. for more information follow these links.Multiple laravelsites on single apache server , multiple web sites in single laravel installation

Apache looks for index.php files in Laravel 5

I am a begginer in Laravel and I am having troubles with Apache 2.2.15 on CentOS 6.5 and Laravel 5. I have searched for this error and I found some solutions for .htaccess and for httpd.conf but none of them are working and i get this error when trying to access "public/auth/register" or "public/auth/login" and even "/home":
Not Found
The requested URL /index.php was not found on this server.
Here is my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
And here is my httpd.conf
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
The only page that works is the public/index.php
You have to point apache to the public folder:
<VirtualHost *:80>
DocumentRoot /var/www/html/public
<Directory "/var/www/html/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Wordpress Permalinks 404 error with HTTPS host

My new permalinks continue displaying a 404 error on my site even after adding the AllowOverride and Rewrite modules parameters. Here is my default-ssl.conf file :
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin vincent.zzz#gmail.com
DocumentRoot /var/www/zzz
ServerName zzz.com.vn
ServerAlias www.zzz.com.vn
<Directory "/var/www/zzz">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Location />
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Location>
#end of custon stuff.....
And here is the normal http part of my apache2.conf file :
<VirtualHost *:80>
ServerName zzz.com.vn
DocumentRoot /var/www/zzz
<Directory "/var/www/zzz">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.php
#force SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent]
</Directory>
Would anyone have an idea ?
Are you sure that mod_rewrite is enabled? Is there a symbolic link to rewrite.load in /etc/apache2/mods-enabled?
You can enable the mod with:
sudo a2enmod rewrite

AllowOverride Not Working - CodeIgniter

I'm attempting to figure out why it is that my .htaccess file isn't working - I'm assuming that I am somehow configuring my 000-default.conf incorrectly.
000-default.conf
<VirtualHost *:80>
ServerName ****.********.me
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js|libs|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
/html is a symlink to /www in my CodeIgniter project. I have removed 'index.php' from $config['index_page'], and the front page of the site loads without any issue. It is when I attempt to access any other page on the site that the issue arises (they will not load unless I add index.php to the beginning of each). I also ran sudo a2enmod rewrite, to no avail. I have also restarted the apache2 service during all of my attempts at fixing the issue. Any ideas?
If you just wanna remove index.php, then here is the steps to follow :
1- set $config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';
2- .htaccess file :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

Laravel pretty URLs and routing not working on LAMP

I created web app with Laravel, which I tested on laravel server ( php artisan serve ) and now I want to put it on LAMP so I can test it further, but something is wrong.
When I visit localhost/public/ I get my home page but when I click on any link inside my app I get Not found error. On the other side, when I manually input localhost/public/index.php/someURL then I get the linked page.
Can someone tell me how to fix this?
This is my .htaccess file inside public directory:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
This is the content of apache2 conf file ( /etc/apache2/sites-available/000-default.conf ) :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory "/var/www/html">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And I enabled mod_rewrite with this command: sudo a2enmod rewrite
I'm using Ubuntu 14.04.
UPDATE:
App is placed inside /var/www/html/
Go to /etc/apache2/apache2.conf file and make sure it looks like this:
<Directory /var/www/html>
Options Indexes FollowSymLinks
Allowoverride All
Require All Granted
</Directory>
You can locate it right after
<Directory /usr/share>
....
</Directory>
Perform mod_rewrite and restart apache and it should work!
This is how I fixed it. I created another .htaccess file and placed it in root directory /www/html/:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Information taken from here: http://driesvints.com/blog/laravel-4-on-a-shared-host

Categories