单个Laravel路由在CloudWays上的Apache中不起作用

单个Laravel路由在CloudWays上的Apache中不起作用

问题描述:

I have a Laravel installation on DigitalOcean through CloudWays in which one of the routes doesn't work. It has nginx serving static content and Apache serving the dynamic pages. Every route works fine, except for the following one:

Route::get('/r/{id}/{url}', 'CampaignController@redirect')
    ->where('url', '(.*)?');

On my localhost through php artisan serve, it works and on another installation on nginx it works fine. This is a client's server and although he has granted my account full access to the server, sudo is disabled and I can't touch anything outside of the public_html directory, so I'm assuming it's doable through .htaccess, here's what I have now:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>  

The problem was that I was URL-encoding another address with slashes and Apache decoded it and interpreted it as a different path while nginx didn't. The solution was to use another encoding.