起因
接著遇見了一個問題
由於laravel 自帶重寫URI的.htaccess,但是無論如何都會導到根目錄下
這時候像我這種路徑就會出問題了
例如本來我寫了一個route
Route::get('/test',function (){ return "test"; });這本來想要觸發的是 https://weijweb.com/weijlab/test
頁面則自動重寫成 https://weijweb.com/test
導致404
過程
既然已經知道是rewrite出問題,那就好解決了
首先把apache的rewrite log打開
設定檔在
root@raspberrypi:/var/www/html/weijlab# cd /etc/apache2/ root@raspberrypi:/etc/apache2# ls apache2.conf conf-available conf-enabled envvars envvars.dpkg-old magic mods-available mods-enabled ports.conf sites-available sites-enabled ssl root@raspberrypi:/etc/apache2# vim apache2.conf中間搜尋LogLevel並修改
# # LogLevel: Control the severity of messages logged to the error_log. # Available values: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the log level for particular modules, e.g. # "LogLevel info ssl:warn" # LogLevel warn rewrite:trace3這樣就可以在log中看見情況了,我這邊直接開了一個console來監控
pi@raspberrypi:/var/log/apache2 $ tail -f error.log 中略 [Sun Sep 02 16:00:38.012469 2018] [rewrite:trace3] [pid 6422] mod_rewrite.c(477): [client 192.168.1.254:5280] 192.168.1.254 - - [weijweb.com/sid#75717900][rid#70280058/initial] [perdir /var/www/html/weijlab/public/] strip per-dir prefix: /var/www/html/weijlab/public/test -> test [Sun Sep 02 16:00:38.012601 2018] [rewrite:trace3] [pid 6422] mod_rewrite.c(477): [client 192.168.1.254:5280] 192.168.1.254 - - [weijweb.com/sid#75717900][rid#70280058/initial] [perdir /var/www/html/weijlab/public/] applying pattern '^/(.*)/$' to uri 'test'現象已經很明顯了,直接到laravel的public下.htaccess做修改
# Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] 最下面這行改成確定重寫的路徑 RewriteRule ^ /weijlab/index.php [L] 存檔離開
驗證
直接打開網頁看route有沒有作動,看起來沒問題了
終於可以開始寫程式囉~~~
留言
張貼留言