mod_rewrite - 我不能让它像我想要的那样工作 [英] mod_rewrite - I can't make it to work like I want

查看:16
本文介绍了mod_rewrite - 我不能让它像我想要的那样工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢阅读.首先,我的根目录中有一个 .htaccess 文件,其中包含以下语句:

Thanks for reading. First of all, I got one .htaccess inside my root directory with the following statement :

# Mod Rewrite
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule     ^$              /root/              [L]
    RewriteRule     (.*)            /root/$1            [L]
</IfModule>

在根文件夹中我得到了这个文件:

and inside root folder I got this file :

# Mod Rewrite
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$          /root/index.php/$1 [PT,L]
</IfModule>

此外,在文件夹 /root 中,我得到了三个文件夹:cssjsimages.

Also, in the folder /root, I got three folders : css, js and images.

我的应用程序被设计为与我的 MVC 框架分离(有点像 CodeGgniter).所以这是树:

My application is designed to be separated from my MVC framework (a bit like CodeGgniter is). So here's the tree :

- application
    - my application files are there
- root
    - css
    - js
    - images
- grecko
    - my mvc framework files are there

这样,我可以更新我的框架,而无需触及在应用程序文件夹下运行的整个网站.

Like this, I can update my framework without touching the entire website who run under the application folder.

无论如何,我现在要做的就是移动我上面说的三个文件夹(cssjsimages)和将它们移动到 /application/assets/ 中.但是由于一切都被重定向到 /root/,我需要一个规则来允许像 http://www.domain.tld/css/blabla.css 这样的请求到映射到/application/assets/css/blabla.css

Anyway, what I would like to do now is to move the three folder I said above ( css, js and images) and move them inside /application/assets/. But since everything is redirected to /root/, I will need a rule that allow request like that http://www.domain.tld/css/blabla.css to be mapped to /application/assets/css/blabla.css, etc.

我确实尝试过,但没有成功.

I did try but without success.

谢谢.

推荐答案

把这段代码放在$DOCUMENT_ROOT/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    RewriteRule ^(css|js|images)(/.*|)$ application/assets/$1$2 [L,NC]

    RewriteCond %{ENV:REDIRECT_STATUS} !200
    RewriteRule ^ root${REQUEST_URI} [L]
</IfModule>

这篇关于mod_rewrite - 我不能让它像我想要的那样工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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