Cannot remove index.php from Codeigniter for Ubuntu - php

The last one I follow is here How to remove index.php from codeigniter in UBUNTU [duplicate]
I have one controller that look like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$this->load->view('login.html');
}
}
When I access it by this URL: http://localhost/homerent/Login, I got 404 not found.
I follow from answer above in referent link by
$config['index_page'] = '';
restart apache2 service: sudo /etc/init.d/apache2 reload
Add below code to /var/www/html/my_ci_site/.htaccess
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|static|robots\.txt|favicon\.ico|uploads|googlexxxxxxxx\.html|mobile.html)
RewriteRule ^(.*)$ index.php/$1 [L]
Replace every instance of AllowOverride None to AllowOverride All in /etc/apache2/apache2.conf
Enable rewrite mode: sudo a2enmod rewrite
Finally restart apache2 service again.
After all, I access my url again http://localhost/homerent/Login I still get 404 not found.
I have no clue what is wrong with that.

In Ubuntu You have to do virtual host to working.
For this first in /etc/apache2/sites-available create yourproject.conf file(may be you may need root permissions use sudo command)
For this in terminal
cd /etc/apache2/sites-available
Then
sudo nano yourproject.conf
Copy below content and paste into it
<VirtualHost *:3434>
ServerName localhost
DirectoryIndex index.php
DocumentRoot /var/www/html/yourprojectfolder
<Directory "/var/www/html/yourprojectfolder">
Options All
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
Note:You can use different ports here
Then run
sudo nano /etc/apache2/ports.conf
In this file add line (Do not edit existing ports )
Listen 3434
Then run
sudo a2ensite yourproject.conf
sudo a2enmod rewrite
in config.php
$config['base_url'] = 'http://localhost:3434';
$config['uri_protocol'] = 'REQUEST_URI';
$config['index_page'] = '';
Create .htaccess inside yourproject folder with below content
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
Then restart apache to take effect the changes
Now you can access your site through the url http://localhost:3434(This will load the defaulf controller) and no need to add the project folder in the url
for example http://localhost/homerent/Login is the url using now and
After setting up virtual host
You can use http://localhost:3434/Login

Related

I cannot remove index.php from URL for Codeinator

I know this question have more answer on this page. But It is not work fine for me. I don't know why. I followed step by step as instruction. Could you please help me check.
Thanks for your support
The URL looks liks is : examplemysite.com
The link work well if I add index.php for it.
Change config.php -> $config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
htaccess is located same level with index.phpenter image description here
The content of htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
In to enable mod_rewrite for Windows and Linux, do the following:
Windows:
Find and open the file .http.conf. This will be located in your Apache install folder.
Make a backup of http.conf which you can restore from, if anything were to go wrong
Find the line #LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’enable-mod-rewrite-1
Locate the block within the directory tags as indicated below and change to:
Options All
AllowOverride All
Finally, restart apache server and your browser. The .htaccess rewriting should now be working.
Linux (Ubuntu as an example):
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 edit the virtualhost
sudo nano /etc/apache2/sites-available/000-default.conf
Below “DocumentRoot /var/www/html” add the following lines:
<Directory “/var/www/html”>
AllowOverride All
</Directory>
Restart the server again:
sudo service apache2 restart

Laravel 5 blank page

I haVE my page hosted in Amazon EC2, it was working well in the root of the apache server (/var/www/html). But i want to have an other page in the same server so i start moving it to a subfolder (/var/www/html/alqip/public) so i can setup the second website in (/var/www/html/page2).
The site is developed in Laravel 5 and it is showing a blank page without login any error in laravel logs and system logs either (syslog, apache logs, php logs).
The permissions of storage folder are 777.
This is my .htaccess in public/ folder:
<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>
And my page.config in /var/apache2/sites-available:
<VirtualHost *:80>
ServerName alqip.com
ServerAlias www.alqip.com
DocumentRoot "/var/www/html/alqip/public"
<Directory "/var/www/html/alqip/public">
AllowOverride All
</Directory>
</VirtualHost>
I think the problem is in Laravel, not in server configuration, what do you think? Thanks!
Verify the firewall is down and if you are on centos check the configuration of the selinux. For default the selinux is enable edit the file /etc/selinux/config
SELINUX=disabled
After disbled you have to reboot you server
after installing Laravel you must create the .env file using the .envexample template.
the next problem you will have is permission issues
Its caused because php is running as another user by default.
so to fix this do
sudo nano /etc/php/7.0/fpm/pool.d/www.conf
then edit the
user = "put user that owns the directories" group = "put user that owns the directories"
then:
sudo systemctl reload php7.0-fpm

.htaccess file with PHP MVC Framework

I am building a website using CodeIgniter PHP MVC Framework, but am having troubles with the routing of the site. I believe the problem is with the .htaccess file that I am using. I have my site at localhost/MyWebsite and the home controller (default) is calling the index action correctly. However, when I try to go to any other Controller/Action (e.g. localhost/MyWebsite/register) route I get a Forbidden Access error. I have a Register Controller with an index action but they were not being found or something. Here is the .htaccess file I am using.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
What do I need to do to make it so all requests are routed to the index.php file in CodeIgniter so that the proper Controllers and Actions can be called?
Are you allowing override within Apache for your .htaccess file to take effect?
Paste the following code within httpd.conf configuration file from Apache:
<Directory "PATH_TO_FRAMEWORK">
Option -Indexes +FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Make share that your files or folder are owned by www-data (whether owner user/group), check with: ls -l
assuming that your OS is ubuntu
if it's not correctly owned then execute:
sudo usermod -a -G your-username www-data
sudo chown your-username:www-data

Laravel 4 remove Index.php from URL

I need some help with laravel 4 application i need to remove Index.php from url i have tried the solution that has been mentioned in laravel documentation
Pretty URLs
Apache
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this one:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
any Suggestions :) ?
FOR LAMP SERVER
Try the following steps,
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
this worked for me
<Directory "/var/www/html">`
AllowOverride All
</Directory>
uncomment 'LoadModule rewrite_module modules/mod_rewrite.so' in apache httpd.conf
in 'public' folder check .htaccess file (created by default)
<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 have read long posts and threads but nothing works then i found this and it works for me.
The easiest way to do this (and the way I always use) is to open up your Command prompt or Terminal and cd into the main directory of your project then run "php artisan serve". That's it. You're done. Don't believe me? Check out http://localhost:8000 and admire your Laravel work.
http://michaelbrooks.co.uk/post/laravel-localhost-removing-public-index-php
just go to your apache settings folder, i use wamp so myne is
C:/wamp/bin/apache/apache2.4.9/conf/httpd.conf - file
// located on line 154 precisely...
#LoadModule rewrite_module modules/mod_rewrite.so
// to
LoadModule rewrite_module modules/mod_rewrite.so
restart WAMP and BOOM!.. it works.
mod_rewrite apache module may not be enabled by default. enable it and retry.
Try this:
a2enmod rewrite
And it will works

web/app.php is not removing in symfony2

i have created first Symfony application but the url is so large
http:// ip address/repair/web/app_dev.php/home
http:// ip address/repair/web/app.php/home
i want to make it as http:// ip address/repair/home
here is httpd.conf of apache2
NameVirtualHost something ip address
ServerName "repair"
DocumentRoot "/var/www/repair/web"
<Directory "/var/www/repair/web">
DirectoryIndex app.php
AllowOverride None
Order allow,deny
Allow from All
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
RedirectMatch permanent ^/app\.php/(.*) /$1
</Directory>
my .htaccess of in web folder of symfony contains
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
i have reloded the mod-Rewrite of apache2 too
iam getting error
The requested URL /repair/home was not found on this server.
Apache/2.2.20 (Ubuntu) Server at ip address Port 80
If you want to access site by ip you need to copy your code to "localhost" directory (/var/www, e.g.)
The AllowOverride None line in your Apache config is causing the .htaccess file to be ignored.
If you replace it with AllowOverride All Apache will follow the directives in your .htaccess file.
You can find more information about AllowOverride here
Double-check that you actually have mod-rewrite loaded for Apache. On a Debian 6 install with Apache 2, the module was available, but it wasn't loaded. In order to load it, you can add a symlink in the mods-enabled directory to the module in the mods-available directory like this:
root#server:/etc/apache2/mods-enabled# ln -s ../mods-available/rewrite.load ./rewrite.load
Then you'll need to restart Apache2 to get it to reload its configuration. On Debian that would be sudo service apache2 restart

Categories