2013-04-08 26 views
0

也許它會顯得很容易,但我有一個與我的.htaccess的問題。我要重寫我的網址,使得<a href="/admin">some text</a>可以作爲<a href=""http://localhost:8888/madison/the-madison-project/admin/index">some text</a>設置全局變量來重寫一些URL - .htacess

所以我設置被改寫:

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] 

回答

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:正如你所看到的,至少有三種形式,從他們的價值觀

+0

事實上它沒有工作,在%捲曲的種族面前似乎並沒有被認可... – user1611830 2013-04-09 13:44:03

+0

@ user1611830我沒有看在'SetEnv'正常。請參閱最新的答案。 – 2013-04-09 15:54:52