0

我的项目中有以下架构:

Application/Modules/Example/Controllers/Views/Web/css/style.css img/Core/index.php

我想将所有 REQUET_URI 重定向到我的 index.php。使用以下 .htaccess 内容很容易:

RewriteEngine   On
RewriteCond     %{REQUEST_FILENAME}             !index\.php
RewriteRule     ^(.*)$                          index.php/$1 [L]

但是现在,如果我请求 www.domain.ext/Application/Modules/Example/Web/css/style.css,它将无法正常工作。这是我所期望的,因为我想为我的“模块”重写 url,例如:www.domain.ext/ModuleName/[...] 上一个链接会给我文件 www.domain.ext/Application/Modules/ModuleName /网络/[...]

例如: www.domain.ext/ModuleName/css/style.css 会给我文件 www.domain.ext/Application/Modules/ModuleName/Web/css/style.css 与 www.domain.ext/ModuleName 相同/my_file.xml => www.domain.ext/Application/Modules/ModuleName/Web/my_file.xml 等等..

但我不知道该怎么做。我想保留所有目录“全部拒绝”。

谢谢 :)

4

3 回答 3

1

你应该使用这个规则:

RewriteEngine On

RewriteRule !^Application/Modules/ Application/Modules/%{REQUEST_URI} [L,NC]

# not already rewritten
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# not a file
RewriteCond %{REQUEST_FILENAME} !-f
# not a directory
RewriteCond %{REQUEST_FILENAME} !-d
# forward to index.php
RewriteRule ^(.*)$ index.php/$1 [L]
于 2013-10-21T13:36:57.847 回答
0

好吧,假设您希望能够访问index.php文件中的 slug,您可以这样做:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !index\.php
RewriteRule ^(.*)$ index.php/?request=$1 [L]
于 2013-10-21T13:30:34.077 回答
0

尝试这个

RewriteEngine on
RewriteBase /

# Rewrite if the file does not exists
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !index\.php

# Rewrite any assets file
RewriteRule ^(.*)/(.*).(css|js|png|jpe?g|xml|gif)$ index.php/Application/Modules/$1/$2.$3 [L]
RewriteRule ^(.*)/(.*)/(.*).(css|js|png|jpe?g|xml|gif)$ index.php/Application/Modules/$1/$2/$3.$4 [L]

这些规则应该重定向:

www.domain.ext/Example/css/style.css

www.domain.ext/Application/Modules/Example/Web/css/style.css

www.domain.ext/ModuleName/my_file.xml

www.domain.ext/Application/Modules/ModuleName/Web/my_file.xml

编辑:对不起,这是我的错误,我做错了规则

根据我的测试,这给了我 500 内部错误:

index.php/Application/Modules/$1/$2.$3 [L]

但是如果我使用 QUERY_STRING?它就可以了

index.php?Application/Modules/$1/$2.$3 [L]
---------^

所以最好使用 QUERY_STRING 变量,例如:

index.php?page=Application/Modules/$1/$2.$3 [L]

并使用以下命令检索 php 中的内容:

<?php

$page = $_GET['page']; // Application/Modules/Example/Web/css/style.css
于 2013-10-21T16:14:05.307 回答