.htaccess file not works in LAMP - php

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

Related

URL Rewriting and Laravel 4 Routes not working on server?

I bet this question has been asked time and time again, but I just can't seem to get an answer. Anyway, here is my situation. I have a domain, lets say example.com. Example.com works fine, everything works as it should. However, if I navigate to Example.com/about, which works on my local machine, I get a 404 error. However, if I go to example.com/index.php/about, the about page works fine. I know this must be a mod rewrite issue. I have enabled mod rewrite and restarted my server to no avail. Anyway, here is some code:
Virtual Host:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/example/public"
<Directory "/var/www/example/public">
AllowOverride all
Allow from All
</Directory>
</VirtualHost>
And here is my .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]
</IfModule>
I'm using Ubuntu 14.04 on a Digital Ocean Droplet.
Thanks!
1)
go to /etc/apache2/sites-available and create file and add below
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#newyear
DocumentRoot /var/www/html/example/public
<Directory /var/www/html/example/public>
options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
2) Create Link of above created file and paste it into /etc/apache2/sites-enabled
3) Check /etc/apache2/mods-available for rewrite.load file
if it is not there create it and add below line & save
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
create link of rewrite.load file and paste it into etc/apache2/mods-enabled
4) open /etc/hosts
add below
127.0.0.1 example.com
5) sudo service apache2 restart
I figured out how to do this, I had to put my VirtualHost code in sites-enabled, not sites-available. Facepalm.
In ubuntu 14.04 with apache2 i was fall this problem.Then i solve this and wrote a blog,you can follow this
http://www.kingpabel.com/apache-mod_rewrite/

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.

URL Rewriting not working with ZF and apache2

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

codeigniter .htaccess in amazon ec2 removal of index.php not working

codeigniter .htaccess in amazon ec2 removal of index.php not working
code
RewriteEngine on
RewriteBase http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
config file
$config['base_url'] = 'http://ec2-xx-xxx-xx-xx.us-west-2.compute.amazonaws.com/';
You can change your .htaccess like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and change the value of "AllowOverride None" on /etc/httpd/conf/httpd.conf (if you use AMI Linux)
into "AllowOverride All"
after that restart your apache with command like this:
sudo service httpd restart
It's work and tested on my aws ec2.
(if you use ubuntu)
Activate the mod_rewrite module with
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">
AllowOverride All
</Directory>
Save and exit the nano editor via CTRL-X, “y” and ENTER.
Restart the server again:
sudo service apache2 restart
Justudin is correct!
Also you can use the "AllowOverride All" rule to only your project; writing in /etc/httpd/conf/httpd.conf something like this:
<Directory "/var/www/your_website">
AllowOverride All
</Directory>
Only you can use the "AllowOverride All" rule to all deployed application; writing in /etc/httpd/conf/httpd.conf :
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

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