Codigniter htaccess error 404 at production - php

i am very begainer to server technologies.i know this question asked too many times but i really don't get it run.
it runs with domain.com/2.0/index.php/testbut when you remove index.php it throws
The requested URL /2.0/test was not found on this server.
Apache/2.2.15 (CentOS) Server at domain.com port 443
my project stucture
-
Public_html
--2.0(this is my project folder where ci can be located.it has sys,app,.htaccess)
--.htaccess
My domain
https://domain.com/2.0/
about the problem
i have two htaccess one at root mention above one is inside 2.0 folder
and the strange thing is what ever i write in the htaccess file it never effect anything
public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
public_html/2.0/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
my httpd.conf
<VirtualHost *:443>
ServerAdmin info#domain.com
DocumentRoot /home/natural/public_html
ServerName api01.domain.net
ErrorLog /var/log/httpd/error_log
CustomLog /var/log/access_log common
SSLEngine on
SSLCertificateFile /home/natural/api01.domain.net.crt
SSLCertificateKeyFile /home/natural/api01.domoin.key
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
</Directory>
</VirtualHost>
i search alot and follow all the answers by Stack overflow but no luck.

The directive "AllowOverride None" in httpd.conf will disable parsing of the .htaccess file within the directories specified (in this case /) -- Can you confirm that either of your .htaccess files are in fact being parsed?
If not, does modifying the Directory subsection within your httpd.conf file to:
<Directory />
Options Indexes FollowSymLinks
Allow from all
AllowOverride All
</Directory>
Solve the issue?
For more information: http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

I assume 2.0 is the new version of the site. It looks like /2.0/.htaccess is written as though it expects to be in the root folder. Try adding RewriteBase /2.0/ after engine on. You can remove it later when you replace the contents of the root folder with that of 2.0's.
The main problem is your # Handle Front Controller... rule. It'll capture any virtual URLs before they ever get to the 2.0 folder. Try changing it to this:
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]
That will exclude the 2.0 folder from the current site's virtual URLs.
You do still need AllowOverride all as recommended by the other answer, and the directory should be the same as your DocumentRoot, not /.

Add this code inside root->.htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteRule ^(?!2\.0(?:/|$)) index.php [L]

Related

How to issue and customize .htaccess for Laravel?

I have just launched a Laravel 5.3 project on a live server and all is going well except one.
But my issue is, My websites are running on all 3 different URL.
My server is Ubuntu 16.4.
website.com
website.com/public/index.php
website.com/ any word /index.php
My .htaccess is: (This file is in the root folder)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)$ public/index.php$1 [L]
</IfModule>
But I just want to see my website with website.com URL only.
Seems like your Laravel app is accesible via an Apache HTTP alias. Follow these steps
Try to navigate to your expected route prepend it with /index.php/, in your case: website.com/index.php/users. If it works (no 404) then you problem is with the Rewrite Module configuration of Apache HTTP, you should follow the next steps.
Edit the file public/.htaccess.
Under the line RewriteEngine On add RewriteBase / if files are on root directory if in folder like laravel then add RewriteBase /laravel/
Try to navigate to an existing route.
i.e
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteRule ^(.*)$ public/index.php$1 [L]
</IfModule>
Remove /public from your Laravel
create a virtual host
go to /etc/apache2/sites-available create .conf file or update 000-default.conf
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName website.com
ServerAlias www.website.com
DocumentRoot /var/www/html/index.html
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =website.com [OR]
RewriteCond %{SERVER_NAME} =www.website.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
To only match the homepage, i.e. http://domainxyz.com/ you need to match the empty path (as mod_Rewrite removes the leading /.
RewriteCond %{HTTP_HOST} ^www.domainxyz.com [NC]
RewriteRule ^$ /view.php?page=process/ [NC,L]
Try using this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.com/([a-zA-Z-]*)/index.php [NC,OR]
RewriteCond %{HTTP_HOST} ^www.website.com/([a-zA-Z-]*)/index.php [NC]
RewriteRule ^(.*)$ http://www.website.com [L,R=302,NC]
Make sure you clear your cache before testing this. You will notice I've used R=302, this is a temporary redirect. If the redirect works and you're happy with it, then switch that to R=301 which is a permanent redirect.
This code worked for me. It will remove extention from your website e.g .php and all. Try it once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
1. I understand why you are trying to change the .htaccess but this can be solved alot simpler. Revert the .htaccess file back to the Laravel standard
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
2. Move all of your folders and files apart from public and make sure they are behind your HTML folder.
3. Move all of your public folders and files out of the public folder and into your html folder
4. Tell laravel to look in your html folder instead of public by altering the server.php file
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylorotwell#gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/html'.$uri)) {
return false;
}
require_once __DIR__.'/html/index.php';
I find this solution a lot simpler than messing around with you htaccess. You also ensure all of the Laravel core files cannot be accessed from a url.
Other issue you are having (Internal pages)
This is probably due to your apache not allowing override with Laravels htaccess
Go to the command line of your server and access the apache2.conf file
cd /etc/apache2
Open the apache2.conf file with nano
sudo nano apache2.conf
Now locate the following
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change this to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Writeout the changes and exit nano.
Restart apache
sudo service apache2 restart
It should now be working :)

Remove index.php from the url with laravel 5

I checked many posts here about removing index.php from url but I could not get the desired results, I already added my local url site name to virtual hosts file (I use wamp) and when I write url like this it work http://first-app.com
My problem when I navigate to another folder like "songs" this url does not work, I get url not found
http://first-app.com/songs
while if I used index.php it work
http://first-app.com/index.php/songs
here is my httpd-vhosts.conf file:
<Directory C:\wamp\www\composer-demo\first-app\public>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\composer-demo\first-app\public"
ServerName first-app.com
</VirtualHost>
Can that be solved from modifying this file ? or I need to modify .htaccess file located at the public folder ? here it is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
All I need was to enable rewrite_module in the apache server then restart, since I use wamp I only selected the module from the list menu
Here is a complete list how it can be done for Mac, Linux and Windows

which one is better to run laravel?

I have installed laravel in my cpanel and localhost, but i found two way to execute/run laravel.
access the
/public/
use
php artisan serve
if i run in my notebook/localhost i can use php artisan serve and it done well like routing and database, but in my cpanel i cant use the second way, so i must use first way, but it not done well like routing and etc.
So which one is better and how to make the first way run well?
Normally, you would use
php artisan serve
on your development environment only.
On production servers, you will add a <VirtualHost> or an Alias drective in your Apache configuration.
<VirtualHost *:80>
ServerAdmin admin#localhost
DocumentRoot /path/to/your/laravel/public
ServerName your.domain.com
<Directory /path/to/your/laravel/public>
AllowOverride None
Order allow,deny
Allow from All
Options FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</Directory>
</VirtualHost>
With this type of configuration, you can access your Laravel site as:
http://your.domain.com/
When using an Alias, your Apache configuration will be something like this:
Alias /any/path/you/want /path/to/your/laravel/public
<Directory "/path/to/your/laravel/public">
Order allow,deny
Allow from All
Options +FollowSymLinks
RewriteEngine On
RewriteBase /any/path/you/want
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</Directory>
With this configuration, you will access your laravel as: http://your.domain.com/any/path/you/want
On some web hosting providers, you don't have access to the Apache configuration,
in which case, you will have to put your configuration in an .htaccess file inside your public directory.
Laravel has a default .htaccess file inside the public directory that contains this:
<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>
You will have to check if your hosting allows .htaccess

The url requested was not found laravel 4

I'm trying to create an app with laravel 4 but i'm facing a url issue. i have wamp installed on my machine. i set up a new virtual host in my httpd-vhost.conf with this code
<VirtualHost mobile.dev>
DocumentRoot "C:\wamp\www\mobile.dev\public"
ServerName mobile.dev
<Directory "C:\wamp\www\mobile.dev">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
Allow from 127.0.0.1
Deny from all
Require all granted
</Directory>
mobile.dev is a folder and also the domain name in my localhost.
here is my Route.php file
Route::get('/','HomeController#showWelcome');
Route::post('login','LoginController#userLogin');
Route::get('login','LoginController#getUsers');
when i ask for mobile.dev/login it gives me the requested url was not found.
can you help me please solve this issue. but when i ask for mobile.dev/ its working.
Here is my .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]
Here is more details. when i remove my htaccess content everything works fine with the default url http://mobile.dev/index.php/login
So the problem is in my htaccess and the rewriting in my virtual host
It might be not Laravel problem, but seems your wamp server haven't enabled mod_rewrite in httpd.conf file yet. Locate the line -
#LoadModule rewrite_module modules/mod_rewrite.so
and remove the comment symbol '#'. Then save the file and restart Apache.
Solution:
1- when you have wamp installed in your machine please go to C:\wamp\bin\apache\Apache*.*.*\conf\httpd.conf and make sure that rewrite_mod is enabled by deleting the hash tag. (instead of using the interface provided by wamp)
2-there are two ways to enable rewriting for laravel 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]
</IfModule>
or using this :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
3- if you're setting a virtual host be sure to add this option in the <virtualhost> tag
<Directory "C:\wamp\www\mobile.dev\public">
Options FollowSymLinks Indexes Multiviews
AllowOverride All
</Directory>
Thanks a lot for your time.
Have you tried
Route::post('login','LoginController#userLogin');
without the () after userLogin?
Your <Directory "C:\wamp\www\mobile.dev"> in config should be <Directory "C:\wamp\www\mobile.dev\public"> to specify the public directory to the root of the htaccess rewrite rules.
I originally thought you were missing the </IfModule> at the end of your .htaccess file but when I posted my .htaccess file it hid the </IfModule> as well so that is a stack overflow issue. Otherwise your htaccess is correct.

Explanation of this .htaccess file

I have recently added a .htaccess file to my website root in order to achieve something I have already asked in this question:
Create blog post links similar to a folder structure
Now, the top answer was brilliant and it worked on localhost, however on my server it doesn't.
To be honest with you, I am not quite sure what these statements in the .htaccess mean exactly. I would be grateful if somebody could explain them line by line.
So this is what I have
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<IfModule mod_rewrite.c> # If the module for rewrite is available
RewriteEngine On # turn it on
RewriteBase / # set / to the relative root path
RewriteRule ^index\.php$ - [L] # don't rewrite index.php and stop the rest of the rules
RewriteCond %{REQUEST_FILENAME} !-f # if file does not exist
RewriteCond %{REQUEST_FILENAME} !-d # and file is not a directory
RewriteRule . /index.php [L] # show the index page instead
</IfModule> # close the IfModule clause
I suspect if it doesn't work on your server, that the root directory isn't set properly for the domain or server configuration. You'll wanna look into where the files are placed and how the httpd.conf is configured to use those paths.
Also, for next time Apache has a wonderful documentation on this module that should cover everything I've just said, in more depth.
The actual problem was that the rewrite was not enabled on my virtualhost.
So I enabled it in my virtualhosts and everything works now.
<VirtualHost *>
ServerName mysite.com
DocumentRoot /var/www/html/mysite.com
<Directory /var/www/html/mysite.com>
Options FollowSymLinks
AllowOverride all
</Directory>
</VirtualHost>

Categories