0

也许它看起来很容易,但我的 .htaccess 有问题。我想重写我的网址,以便<a href="/admin">some text</a>可以重写为<a href=""http://localhost:8888/madison/the-madison-project/admin/index">some text</a>

所以我设置了这个:

SetEnv root:/madison/the-madison-project/
RewriteRule ^admin[/]?$ {%ENV:root}admin/index

但它不起作用。

我该如何解决?

编辑:经过几次尝试,我发布整个 .htaccess 文件可能更简单

RewriteEngine On
ExpiresActive On

#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "now plus 7 days"
</FilesMatch>

ExpiresByType text/css "now plus 7 days"
ExpiresByType text/html "now plus 7 days"
ExpiresDefault "now plus 7 days"

AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css

SetEnv root:/madison/the-madison-project/
#SetEnvIf Request_URI ^ root=/madison/the-madison-project/
#RewriteRule ^ - [E=root:/madison/the-madison-project/]

RewriteRule ^(assets|inc) - [L]

RewriteRule ^admin[/]?$                         %{ENV:root}admin/index

RewriteRule ^admin/edit/(.*)$                   %{ENV:root}index.php?type=admin&action=edit&page=$1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^admin/(.*)$                        %{ENV:root}index.php?type=admin&action=view&page=$1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^login$                             index.php?action=view&type=login&%1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^forgot-password$                   index.php?action=view&type=forgot-password&%1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^edit/user(/)?$                     index.php?action=edit&type=user&%1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^signup(/)?$                        index.php?action=edit&type=user&id=0&%1  [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^user/([0-9]+)(/)?                  index.php?action=view&type=note&user=$1&%1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^(suggestion|comment)/([0-9]+)(/)?  index.php?action=view&type=note&page=open&note_type=$1&note=$2&%1 [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)/(suggestion|comment)/([0-9]+)(/)?    index.php?action=view&type=note&page=$1&note_type=$2&note=$3&%1 [L]

#Catch All Pages
RewriteRule ^index\.php$ - [L]

RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)(/)?          %{ENV:root}index.php?action=view&type=page&page=$1&%1 [L]
4

1 回答 1

1

有两个问题SetEnv

  • 变量和值用空格而不是冒号分隔
  • 笔记

    该指令设置的内部环境变量是在大多数早期请求处理指令运行后设置的,例如访问控制和 URI 到文件名的映射。如果您设置的环境变量是作为早期处理阶段的输入,例如 RewriteRule 指令,您应该改为使用SetEnvIf.

例如,这将是

SetEnvIf Request_URI ^ root=/madison/the-madison-project/

或者,您可以使用非重写规则来设置环境变量

RewriteRule ^ - [E=root:/madison/the-madison-project/]

最后,你必须把百分号%放在花括号前面

RewriteRule ^admin[/]?$ %{ENV:root}admin/index

PS:如您所见,至少有三种形式将环境变量与其值分开

于 2013-04-08T17:58:14.090 回答