我用这个.htaccess:
Options +SymLinksIfOwnerMatch -MultiViews
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#redirect to trailing slash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [L,R=301]
RewriteRule . index.php
我使用URLManager(yii2框架)中的下一个代码:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<username:\w+>'=>'site/user',
],
我发现动态css和js没有加载。我知道与我的重定向规则一致的问题。但我该如何解决呢?
答案 0 :(得分:1)
您需要重新排序指令,如下所示:
Options +SymLinksIfOwnerMatch -MultiViews
IndexIgnore */*
RewriteEngine On
#redirect to trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.+)$ http://%{HTTP_HOST}/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]