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>
Related
I have recently installed the lamp stack and have enabled mod_rewrite:
$ sudo a2enmod rewrite
$ service apache2 restart
I can see it on my phpinfo:
But when I try to access an URL like this below in my WordPress:
http://my-localhost/my-wordpress/whats-on/
I get this error:
Not Found
The requested URL /my-wordpress/whats-on/ was not found on this
server.
Apache/2.4.18 (Ubuntu) Server at 127.0.0.1 Port 80
What else can I do? Have I missed anything?
Any ideas?
I have my .htaccess on too:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my-wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my-wordpress/index.php [L]
</IfModule>
# END WordPress
But why?
EDIT:
I created a simple test:
RewriteRule ^test.html$ test.php [L]
But i get 404 error instead of being directed to test.php
Not Found
The requested URL /mod_rewrite/basic/test.html was not found on this server.
Apache/2.4.18 (Ubuntu) Server at 127.0.1.1 Port 80
How can I fix this?
To fix this issue follow this:
sudo nano /etc/apache2/apache2.conf
Find:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Replace With:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Exit and save and restart apache with command
sudo systemctl restart apache2
THE END :-)
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
I am newbie in Codeigniter and trying to configure Codeigniter.
But i am unable to remove the index.php from url..
I changed the .htaccess file by following data which was given in userguide..
.htacess file contains
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and also changed the config file
$config['index_page'] = '';
when i try to use the following url it results
The requested URL /codeigniter/pages/view was not found on this server.
http://localhost/codeigniter/pages/view
But i try with index.php in url..The page shown normally..
http://localhost/codeigniter/index.php/pages/view
Is that .htaccess problem or i have to change some other files..?
How to get rid of this problem?
Any Suggestions, acceptable.
Update
I am using ubuntu 3.10
I used the following command to enable module rewrite
sudo a2enmod rewrite
The result as follows
Module rewrite already enabled
I changed the permissions in
/etc/apache2/sites-enabled/000-default
As
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
After changing this file also no luck..
Finally i found the answer to my question.As the below .htaccess solved my problem..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?/$1 [L,QSA]
</IfModule>
Thanks to all..
in your httpd.conf (on windows)
uncomment below line
LoadModule rewrite_module modules/mod_rewrite.so
in ubuntu
enable mod_rewrite using sudo a2enmod rewrite
Restart apache after making changes
Make this changes
In config.php
$config['index_page'] = '';
IN root .htaccess file
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|themes|utils|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L]
Nobody mentioned change the setting. In your httpd config file find and change it like this
<Directory "/var/www/html"> # your DocumentRoot setting
Options FollowSymLinks
AllowOverride All # default is None
Order allow,deny
Allow from all
</Directory>
I am following the quickstart of laravel and it said "type /users" but not working for me.
I have wrote in the browser, http://DomainServer/ProjectName/users and it throws:
The requested URL /ProjectName/users was not found on this server.
Laravel
I tried the following,
To enable the apache module mod_rewrite and also does not work.
Steps for Apache Web Server and Laravel in Linux Environment.
Open httpd.conf
sudo vim /etc/httpd/conf/httpd.conf
# for debian users: /etc/apache2/apache2.conf
Make sure the DocumentRoot is pointing to the laravel project's public directory
Add the Directory element for that path and Allowoverride All... as follows
DocumentRoot "/var/www/html/laravel/public/"
<Directory "/var/www/html/laravel/public">
Allowoverride All
</Directory>
Open .htaccess from ../laravel/public/ and make sure it has the following
<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>
Restart httpd services
sudo service httpd restart
Now http://DomainServer/users will work in your browser.
Find httpd.conf and change the <Directory> element from
<Directory "/var/www/html/">
Allowoverride None
</Directory>
to
<Directory "/var/www/html/">
Allowoverride All
</Directory>
Then it works after restart the apache without change the DocumentRoot.
First find the htaccess file in your Laravel project
next add the following coding in htaccess file
<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]
save the htaccess file
and restart the apache server using following code
sudo service apache2 restart
remember htaccess file and index.php file must be available in same folder in your project
the default url have a prefix "index.php" before your page if you try .../public/index.php/your_page it will run, so you need to add the module rewrite if you are using appache to write your url without this prefix
Try pointing your browser to http://DomainServer/ProjectName/public/users - the 'public' folder is the default 'entry point' for your Laravel app.
Make sure you have mod_rewrite enabled in Apache .
For me i enabled the mod_rewrite and it worked for me well.
Enable mod_rewrite for Apache:
cd /etc/apache2/sites-available/
sudo a2enmod rewrite
in my case I wanted to get this route as not authenticated user .
RouteServiceProvider has default :
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* #return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
which means you need to add that prefix "api/" to your url, say:
http://yourdomain.com/api/route_url_part
Then put route to api.php , not web.php wich is auth 'middlwared'
(optionally for Android emulators)
if you are trying to do that in, say, android emulator you have to shut down server and start it as:
php artisan serve --host=0.0.0.0
and in java android url instead of localhost put in the ip retrived from prompt window's ipconfig command. Say mine was 192.168.0.106
(IPv4 Address one). Then it will work.
$ sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Change to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
$ sudo a2enmod rewrite
$ sudo systemctl restart apache2
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 :)