如何修复的.htaccess使用mod_rewrite的规则? [英] How to fix .htaccess with mod_rewrite rule?

查看:209
本文介绍了如何修复的.htaccess使用mod_rewrite的规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个的.htaccess:

I use this .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

我用的是下一个code中的URLManager(yii2框架)内:

I use the next code inside the URLManager (yii2 framework):

   'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<username:\w+>'=>'site/user',
            ], 

我发现,动态CSS和JS不会加载。我知道,在我的重定向规则的行问题。但是,我怎么能解决这个问题?

I found that dynamic css and js doesn't load. I know that problem in the line with my redirect rule. But how can I fix it?

推荐答案

您需要重新安排你的指令是这样的:

You need to reorder your directives like this:

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]

这篇关于如何修复的.htaccess使用mod_rewrite的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆