也许这看起来很容易,但我的.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¬e_type=$1¬e=$2&%1 [L]
RewriteCond %{QUERY_STRING} ^(.*)?$
RewriteRule ^([0-9A-Za-z\-_]+)/(suggestion|comment)/([0-9]+)(/)? index.php?action=view&type=note&page=$1¬e_type=$2¬e=$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]
答案 0 :(得分:1)
此指令设置的内部环境变量在大多数早期请求处理指令运行后设置,例如访问控制和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 :正如您所看到的,至少有三种形式将环境变量与其值分开
SetEnv
var value SetEnvIf
条件 var = value RewriteRule
模式替换[E=var:value]