1

I actually thought there should already be a thread about this but i wasn't able to find one.

let's say i have a website with this structure:

/index.php
/.htaccess
/template
/template/css
/template/css/foo.css

I'm redirecting everything to index.php with .htaccess

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

Now I've got a problem with the css. that i could fix by placing another .htaccess in /template with this

RewriteEngine off
Options -Indexes

And then access the css file with http://example.com/template/css/foo.css but actually i would prefere to have just http://example.com/css/foo.css

So i tried to put in /.htaccess the following code (that didn't worked). What did i do wrong?

RewriteEngine on
RewriteBase /
RewriteRule ^/css/(.*) www/css/$1 [L]
RewriteRule ^/js/(.*) www/js/$1 [L]
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

note I don't have any .htaccess in /template!

4

1 回答 1

1

您应该删除 css 文件夹中的 htaccess 文件。您只需要排除对模板目录的重写。您可以在一个文件中完成所有操作:

RewriteEngine on
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/template/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /template/$1 [L]

RewriteCond ${REQUEST_URI} ^/template/
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]

第一条规则处理对 css 目录的请求,第二条规则是您拥有路由到 index.php 的规则,除非请求是针对模板的。

于 2013-11-14T01:12:20.723 回答