Apache& mod_rewrite - 找不到索引

时间:2015-09-09 14:54:27

标签: regex apache .htaccess mod-rewrite

除了index或'{1}}之类的“索引目录”中的任何内容都会失败之外,这样可以正常工作。

index/foo

我试过这个,但它仍然没有抓住它:

RewriteEngine on

# base dir
RewriteBase /project/

# allow assets/ directory
RewriteRule ^(assets)/(.*)$ $0 [L]

# direct all else to index.php
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1?%{QUERY_STRING} [L]

1 个答案:

答案 0 :(得分:1)

试试这段代码:

Options -MultiViews
RewriteEngine on
# base dir
RewriteBase /project/

# allow assets/ directory
RewriteRule ^(assets)/(.*)$ $0 [L]

# direct all else to index.php
RewriteRule ^((?!index\.php$).*)$ index.php/$1 [L,NC]

MultiViews使用选项Apache's content negotiation modulemod_rewrite之前运行,并使Apache服务器匹配文件扩展名。因此/file可以在网址中,但它会投放/file.php