Redirecting index.php links doesn't work
JoshMountain opened this issue · 1 comments
I have an older site that is being converted to a new Laravel app. I'm attempting to redirect some of the old URLs to new Laravel routes, the problem being that the old site prefixed all URLs with index.php/
. My laravel-missing-page-redirector.php
looks like this:
<?php
return [
/*
* This is the class responsible for providing the URLs which must be redirected.
* The only requirement for the redirector is that it needs to implement the
* `Spatie\MissingPageRedirector\Redirector\Redirector`-interface
*/
'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class,
/*
* When using the `ConfigurationRedirector` you can specify the redirects in this array.
* You can use Laravel's route parameters here.
*/
'redirects' => [
'/index.php/page1' => '/page1',
'/index.php/page2' => '/page2',
],
];
This doesn't seem to work as expected, I'm guessing because the app is trying to load the actual index.php
file in the public directory. I'm not sure if an issue here is the right place for this, but any suggestions would be appreciated.
I ended up solving this with some nginx magic. I added some redirect config stuff from this post on Laracasts: https://laracasts.com/discuss/channels/general-discussion/remving-indexphp-completely/replies/284660
and changed my redirects config to simply:
<?php
return [
/*
* This is the class responsible for providing the URLs which must be redirected.
* The only requirement for the redirector is that it needs to implement the
* `Spatie\MissingPageRedirector\Redirector\Redirector`-interface
*/
'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class,
/*
* When using the `ConfigurationRedirector` you can specify the redirects in this array.
* You can use Laravel's route parameters here.
*/
'redirects' => [
'/page1' => '/page1',
'/page2' => '/page2',
],
];