3

Let's say there's a web-based PHP project which uses an independent framework and also contains a folder with Laravel 4.2:

project/
    laravel/ (Laravel install)
        app/
            routes.php
        public/
            index.php
    index.php
    test.php
    .htaccess

The .htaccess file rewrites every query to the independent framework's index.php, unless a PHP script is requested (e.g., project/test.php).

In this case, test.php contains require laravel/public/index.php to include Laravel's index.php script. The URI to access this is http://example.com/test.php.

How can I make use of Laravel's routing to pick up on this script? I've tried this:

Route::get('/test.php', function()
{
    echo 'success';exit;
});

But that doesn't work (I've tried test.php and just test). Dumping Route::getCurrentRoute() outputs this:

object(Illuminate\Routing\Route)[126]
  protected 'uri' => string '/' (length=1)
  ...
  protected 'compiled' => 
    object(Symfony\Component\Routing\CompiledRoute)[135]
      ...
      private 'staticPrefix' => string '/' (length=1)
      ...

Is it possible to access http://example.com/test.php and have Laravel's Routing see it as if /test or /test.php has been requested, without making changes to the independent framework's .htaccess file?

6
  • 1
    I don't understand what you need. Would you like to serve the /test.php URL through Laravel even though it's a physical .php file on the server? That won't work. Laravel's rewrite rules explicitly make physical files take precedence over internal routing. Do it the other way around: move it in a non-public path and then set it up as a normal Laravel route and require resources from the external application. Commented Jan 8, 2015 at 11:56
  • Well, basically, I want to use the script test.php as an entry point to a controller. I'd like to write a route in Laravel to connect the route /test.php to a controller. Commented Jan 8, 2015 at 12:02
  • Why do you wanna do that? What are you doing inside text.php? Commented Jan 8, 2015 at 12:23
  • Because I want to learn if it's possible to use Laravel's routing system can be manipulated to work that way without touching its source. Essentially I don't have to do anything inside of test.php, just including Laravel's index.php. Commented Jan 8, 2015 at 12:25
  • 1
    You can implement your custom routing classes: github.com/pixeloution/laravel-custom-router Commented Jan 8, 2015 at 12:40

1 Answer 1

1

You are not forced to use Laravel routing, you can bypass it with pure PHP:

if($_SERVER['REQUEST_URI'] === '/test.php')
{
    exit('success');
}

But in your case, you probably should redirect all requests to Laravel with the .htaccess and fall back to root index.php when Laravel does not handle the page:

App::missing(function($exception)
{
    include('../../index.php');
    exit;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.