I'm currently hosting several applications on a quite out-dated wamp version but that's not really the case. Everything is working fine on that part, besides my laravel application.
My .htaccess in the www folder looks like this;
RewriteCond %{HTTP_HOST} ^sapdfr.org$ [NC]
RewriteRule ^((?!sapdfr/websitev3).*)$ /sapdfr/websitev3/public/$1 [NC,L]
The thing that's strange, is that the first page is working but when I'm going deeper into the website, it just totally breaks. I've been trying to rewrite these rules but I'm seriously mindblown about all the possibilities. Any help will be greatly appreciated since I'm entirely lost here.
Maybe a silly question but have you try that ? :)
Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.
If the .htaccess file that ships with Laravel does not work with your Apache installation, try this alternative:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
and then just redirect your domain to the laravel public folder
Related
We have registered account for hostinger and uploaded the Laravel 7 projects into the server and followed the steps from the following URL. But our projects are under the domains folder and as follows in the below picture
When accessing the URL, the default route is working but the other pages are not working and show error as the page is lost. Please suggest to us the right way to achieve this.
Thanks in advance.
It is probably due to rewrites rules are not enabled.
Is there any .htaccess in your public folder ? Maybe try to add the correct laravel 7 .htaccess with the needed rewrites rules.
public_html/.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have multiple codeigniter sites setup like so:
/CI_Site1
/CI_site1/CI_Site2
/CI_site1/CI_Site3
Right now to use my the second and and third site I have to do it like so:
mydomain.com/CI_Site2/index.php/controller/function
If I don't put the index.php then it throws up a 404 in the root site(AKA CI_Site1).
How should I configure htaccess or apache site conf or CI config files such that I don't have to add index.php?
I think the first step should be to configure the routes in CI_site1 to not process requests for the other 2 but I don't know how. Here is hoping a Codeigniter pro can help me.
Thanks in advance.
EDIT: I know how to remove index.php from URLs with htaccess. But that is not the issue here. How do I prevent CI_site1 from processing requests that are for CI_site2 and CI_site3?
Just add below code in file and save it as .htaccess then upload it to Project folder
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
Make sure your server mod_rewrite is on.
Did you try using routes?
$route['CI_Site1'] = '/CI_Site1';
$route['CI_Site2'] = '/CI_site1/CI_Site2';
$route['CI_Site3'] = '/CI_site1/CI_Site3';
I realized that no extra configuration was required. It is sufficient to use .htaccess to remove index.php. My issue was that apache was blocking .htaccess files in its default configuration. Editing apache2.conf to allow processing of htaccess files resolved my issue.
Problem:
my routes not working except the root home page, I'm searching for two days to find a solution to this problem and what I found that I should change .htaccess file but solutions didn't fix any for my case, at first the url localhost/quotes/public was working well with me, but at some point I'm not sure what is it this issue showed up
what I tried:
create another route and I made sure that no routes are working only
home route, still not working except home
tried to change OverrideMode on my XAMP from None to All, didn't fix any
tried to type manually localhost/quotes/public/index.php BOOM everything
works ..
my htaccess file:
<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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
working on:
Windows 10
XAMP
Laravel 5.2.35
The problem is that your .htaccess is rewriting everything to the frontcontroller, which is normally located at {host}/index.php. In your application however it is located at {host}/quotes/public/index.php.
So you have 2 options:
1. virtual host
Set up a virtual host in your XAMPP Apache that points ie. myapp.local to htdocs/quotes/public Here is an example of how to achieve this: how to create virtual host on XAMPP. (Don't forget to add the host to your hosts file and have it point to your local macine on 127.0.0.1) You can then access your application on myapp.local/whatever-route-you-define. Alternatively you forget about XAMMP and install the homestead virtual machine, which comes preconfigured for this.
2. rewrite rule
Change you rewrite rule to rewrite all requests to quotes/public/index.php in stead of index.php. I'm no htaccess expert, but I believe it should be as simple as changing this:
RewriteRule ^ index.php [L]
to this:
RewriteRule ^ quotes/public/index.php [L]
Do note that you'll still need to access your application trough localhost/quotes/public/whatever-route-you-define which is not ideal imo. Your dev version should be as close to your live version as possible, and if you start working with absolute and relative paths and stuff in your code things will become a mess sooner rather then later.
Personally I would go for Homestead, I use it all the time and it works great once you have it running.
Btw, the reason why localhost/quotes/public/index.php is working for you right now is because RewriteCond %{REQUEST_FILENAME} !-f tells Apache not to rewrite any requests to files that actually exist (otherwise you wouldn't be able to access static assets like your css).
The .htaccess file must be at the root of the application.
Add this in this file :
RewriteEngine On
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
Assuming you haven't touched the original architecture of Laravel, and that public data is still in the same place : the public/ folder
You can also follow this good tutorial
Let me give you an example of the way I have my routes setup.
In app\Http\routes.php, here are three sample routes that I have.
Route::get('/', function () {
$values = app('App\Http\Controllers\KeywordController')->index();
dd($values);
return view('welcome');
});
Route::get('googlefile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileGoogle();
dd($output);
});
Route::get('bingfile', function () {
$output = app('App\Http\Controllers\KeywordController')->printToFileBing();
dd($output);
});
I have WAMP setup on my environment. I have made a controller at app\Http\Controllers\KeywordController.php. If my browser is set to localhost/googlefile, then it will goto the method printToFileGoogle() in KeywordController.php.
Please try something similar to this and tell me if you get an error and if you do what error you get.
I have a production copy and a test copy of my website on bluehost. Each website is in it's own directory in public_html folder, one named prod another named test. According to bluehost knoweldge base here: https://my.bluehost.com/cgi/help/347 you setup an htaccess file to rewrite requests coming into the public_html folder to my prod folder. This works pretty well thus far. Something I noticed recently though was with these rewrite settings that if you attempt to load a website file from another directory inside the main website folder e.g. /prod/testfolder without a forward slash on the end it will redirect you to www.mysite.com/prod/testfolder/ instead of staying on www.mysite.com/testfolder. This condition does not happen if you specify the extra forward slash like so.... www.mysite.com/testfolder/
Here is my rewrite rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/prod/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /prod/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ prod/index.php [L]
I'm not an expert when it comes to rewriting urls using htaccess however I suspect the first chunk of rewrite rules is the cause of this. BTW an example of why this makes a difference is that I setup a blog on this site and if you attempt to visit the blog at www.mysite.com/blog it redirects to www.mysite.com/prod/blog/ which defeats the purpose of using htaccess to mask the prod folder in the first place. Can anyone tell me how I should go about fixing this and maybe explain why it's happening? Thank you!
Hello and thank you for taking the time to help me solve my problem. I like to build all of my web projects using a simple MVC Framework I have created along my travels. I seem to be having a problem getting the .htaccess file to work correctly on specific servers.
For example...
If you go to:
http://thomsonbrothersindustries.com/northside/ and attempt to access a page (right now only "About Us" is functional - http://thomsonbrothersindustries.com/northside/about) but as you can see the "about" page just directs you to a 404 Error.
Now, if you go to: (the same site, but on a different server)
http://ericzdisposal.com/northside/
http://ericzdisposal.com/northside/about
everything works fine...
Here is the .HTACCESS file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
My privileges are limited on the server that is currently not working and I'm still working on getting better access to domain tools, but in the meantime I'm just trying to get a better idea of the problem and hoping there might be an easy fix in my future.
In addition to what #bigman suggested, make sure that AllowOverride directive setting is not very restrictive for your website directory. For mod_rewrite to work in .htaccess, you need to set AllowOverride FileInfo, but for testing purposes, you can set AllowOverride All.
Looks like adding the directory into the .htaccess file did the trick!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ **/northside/**index.php?rt=$1 [L,QSA]
I didn't realize this was important because on the other server it did not matter
Thanks all!