Laravel 5 - Home Page Route - php

I have a route issue, I can't point localhost/test/ into my index page of my site.
When I define a route like:
`Route::get("/",IndexController#index);`
localhost/test/ would work fine , but also localhost/test/admin, localhost/test/en localhost/test/foo localhost/test/undefined-route and will load my index page of the site.
and beside when I have namespace Route like:
Route::group(['namespace'=>'Admin'],function(){
Route::controller("admin"=>"AdminController");
})
If I type localhost/test/foo/admin everything works fine but when I write:
localhost/test/admin just my index page of the site.
I don't know whats wrong here, Route problem or .htaccess redirecting my and I'm not aware of it.
Sorry for code misspelling I just wrote what I recall from last night.
Note:: I have an index file in my root directory
my .htaccess file of my root directory is like below, and I replaced the server.php file of my root directory with my index.php file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
and my .htaccess file of my public directory is like default.

Upgrading to Laravel 5.3 seems to Solved the Route Issue,

why don't you run (from terminal):
php artisan serve
then test your project at: http://localhost:8000/ instead of: http://localhost/test/
or if you are using apache, add new virtual host

Related

Laravel document root in a public hosting

I just deployed a Laravel app into Hosting site, and place it into their folder like this:
"example.com/public_html/{All files in a laravel directoy}"
Now, if open in a browser, https://example.com it will show error
Fatal error: require(): Failed opening required '/home/customer/www/example.com/public_html/public/../vendor/autoload.php' (include_path='.:/usr/local/php74/pear') in /home/customer/www/example.com/public_html/public/index.php on line 34
my routes/web.php looks like this:
Route::get('/', function () {
return redirect()->route('login');
});
I already ran composer install and add htaccess to the inside public_html folder
The htacess, looks like this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
Is my htaccess wrong, or is there any additional setup for Laravel if using htaccess to point index.php to public folder?
Note:
The hosting site, set the default document root to public_html and I can not change it. So in order to point to the public folder, I need to create .htaccess file
Place .htaccess file to your root folder and activate mod_rewrite.
Here's an example of what the file should contain without determining specific addresses:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
I think that it doesn't work in your case because of the condition rules.
Copy the Laravel contents in a directory that's hidden from the outside, one different than public_html. Let's suppose that it's /home/user1/myapp.
Move the contents of the Laravel public directory to the public_html. So, you should move /home/user1/myapp/public/* to example.com/public_html
Change the relative routes inside index.php to point to the directory of the first step.

Codeigniter Routing not working on Production Environment

I have codeigniter running fine on my local machine but when I push to the server the routing falls apart. For my set up codeigniter runs from a sub directory named 'secure', so this is the .htaccess file I have created in the 'secure' directory:
RewriteEngine on
RewriteBase /secure/
RewriteRule ^assets/less/icons/(.*)$ /secure/assets/icons/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
The routes file currently looks like this:
$route['logout'] = "secure/logout";
$route['passwordReset'] = "secure/PasswordReset";
$route['default_controller'] = 'secure';
On my local set up if you were to go to the URL '/secure/dashboard' controller 'Dashboard.php' is correctly called and index initiated. However if I go to the same URL on the server it is trying to call the controller 'Secure.php' instead of 'Dashboard.php'.
I'm not sure what is different between my local environment and the server thats stopping the server ignoring the 'secure' part of the URL, I thought that this line in the .htaccess file should sort out the sub directory: 'RewriteBase /secure/'.
Any feedback is very welcome right now :/
I finally got to the bottom of the issue. My server holds a few different environments for development which do not run directly from the http root directory. This was causing the variable $_SERVER['SCRIPT_NAME'] to equal '/staging/secure/index.php' instead of '/secure/index.php';, so I simply added the following to the top of the index.php file
$_SERVER['SCRIPT_NAME'] = '/secure/index.php';

Apache Rewrite rule with Laravel not working

I have the following directory structure:
/home/username/public_html
my_laravel_app/
.htaccess
app/
bootstrap/
public/
.htaccess
index.php
robots.txt
...etc (standard Laravel 4 public folder contents)
vendor/
...etc (standard Laravel 4 files and folders)
I am trying to use an apache RewriteRule to redirect a request to http://example.com/~user/my_laravel_app to http://example.com/~user/my_laravel_app/public/index.php. In the first .htaccess file (the one directly under the my_laravel_app/ directory, I have the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php [R]
</IfModule>
When I navigate my browser to http://example.com/~username/my_laravel_app, I correctly get redirected to http://example.com/~user/my_laravel_app/public/index.php, and the laravel application loads as expected displaying the route for / as defined in app/routes.php.
However, I want the redirect to be internal, meaning, I don't want the users browser to display the new location. So, I simply remove the [R] flag on the rule. The .htaccess file now contains:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php
</IfModule>
Now, when I direct the browser to http://example.com/~username/my_laravel_app I get a Laravel whoops error page saying there was a NotFoundHttpException. When I look at the error page, it seems as though the redirect is "working", because I see that the SCRIPT_NAME is /~username/my_laravel_app/public/index.php.
However, I believe the issue is possibly that the REQUEST_URI is /~username/my_laravel_app/, instead of '/', as it would be if Laravel were installed in the root of a domain like normal. So it seems as though Laravel is looking for a route match using this REQUEST_URI variable.
Is there any way to get Laravel to recognize the correct route?
I had the same issue on Laravel 4.1, and appears related to my apache config, however, I did find a workaround which was to add the following to the top of the public/index.php:
$_SERVER['SCRIPT_NAME'] = 'path/to/laravel/index.php';
// note: this is a workaround for mod_rewrite and laravel which updates the script_name from /path/to/laravel/public/index.php to /path/to/laravel/index.php. I forget exactly why this worked, but I think when I traced the problem back it was related to something in a symfony dependency.

Relative path to sub-directory in PHP and Apache's htaccess file

I am working on my own PHP Framework. I am currently developing it on localhost and everything related to project is in subfolder called RuddyPhpFramework, so the path look like this:
localhost/RuddyPhpFramework/
In that folder, I do have index.php, the init point of whole Framework. I am currently working on my own router, but I have a two problems. First, in Apache's htaccess file a have this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) RuddyPhpFramework/index.php [L]
So whenever someone acces a page like this:
localhost/RuddyPhpFramework/something/smtelse/
The index.php will init the application and echo a path for me, which is:
[path] => /RuddyPhpFramework/something/smtelse/
But that is not excatly what I want. What I want is to get a relative path to subfolder (I don't know if I am explaining this correctly), for example:
[path] => /something/smtelse/
And another problem is that I want to setup the htacces so the last line would look something like this:
RewriteRule (.*) index.php [L]
So it will go for the index.php in the folder where is the htaccess file (/RuddyPhpFramework/index.php) and not /index.php, without specifying the foler, because if someone else will be using the framework, he might have it in a folder with different name.
first please stop we have enouth frameworks already. Now regarding your question. Your project is in localhost/RuddyPhpFramework so htaccess read url from first / so he skips localhost because it's domain and taiks uri witch starts from /
so you project setup is incorrect. what you could try not shure 100%:
RewriteEngine On
RewriteBase /RuddyPhpFramework/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php [L]
please try it. and say did it helped.

URL Rewriting in codeigniter rewrite the URL for next page after login

I'm having a hardtime on this part. Well I created a login page using codeigniter wherein the whole path would be http://localhost/CodeIgniter_2.1.3/index.php will be rewritten into http://localhost/login using .htaccess. Well it works just fine but the problem is after I made a successful login and the page redirects to next page using redirect('next_page'); since the URL would be http://localhost/CodeIgniter_2.1.3/index.php/next_page instead of http://localhost/next_page. I also created a rewriterule for that part :
RewriteRule ^events$ /CodeIgniter_2.1.3/index.php/events [L,NC]
and whenever I key in the http://localhost/next_page in the addressbar the page would appear just fine (since I haven't applied any rules on login and on this page.) I also tried using redirect('http://localhost/events'); this also works just fine but still I know this is not the real solution for this. Oh by the way my .htaccess exists on the www folder of wampserver. Any way to solve this?
First of all your domain ROOT folder should be the codeigniter folder
forexample
c:/www/codeigniter_2.1.3/
just move the files from the codeigniter_2.1.3 to your root folder OR make the codeigniter folder ROOT.
Then use just normal .htaccess rewrite as:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
And use the Codeigniter ROUTER to make your pages as you want them
example:
$route['login'] = 'welcome/login';
Will set http://localhost/login page to be loaded from the Welcome controler Login function.
You can set $routes at your routes.php in the config folder.
P.S> If you want not to see index.php on each page check your Config/config.php for the index_page and make it blank.
You might just want to add virtual host to your localhost. here is one step by step explanation on how to do that.
now all you have to do is create an .htaccess file inside your CodeIgniter_2.1.3 folder that will remove only the index.php in the url.

Categories