在.htaccess中复制这些AliasMatches?

时间:2014-08-19 17:06:51

标签: apache .htaccess mod-rewrite url-rewriting

我最近购买了一个应用程序的共享主机,该应用程序之前在本地服务器上通过Apache虚拟主机配置运行良好。但是,我的共享托管服务提供商(像大多数人一样)不允许客户访问httpd-conf文件,这意味着我必须在.htaccess文件(或多个)中模拟配置。这会出现问题,因为.htaccess不支持<VirtualHost>配置,包括非常重要的AliasMatch指令。所以我向社区提出的问题是如何使用RewriteRulesRedirects复制以下AliasMatches:

AliasMatch /app/(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf)$  "c:/wamp/www/siteroot/app/$1.$2"
AliasMatch /i18n/(.*)\.json$  "/wamp/www/siteroot/app/i18n/$1.json"
AliasMatch /(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf|csv)$      "c:/wamp/www/siteroot/adminApp/$1.$2"
AliasMatch /rest/(.*) "C:/wamp/www/siteroot/rest/$1"
AliasMatch /img/(.*)  "C:/wamp/www/siteroot/adminApp/img/$1"
AliasMatch /(.*)      "C:/wamp/www/siteroot/adminApp/index.html"

文件路径显然会相应更改。这似乎太明显了:

RewriteRule {regex} {filepath} [R=301]

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

您可以删除根部分,然后使用L代替R=301(将从外部重定向,导致浏览器请求新网址并更改位置栏中的内容):< / p>

RewriteEngine On

# this is to prevent looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteRule ^app/(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf)$  /app/$1.$2 [L]
RewriteRule ^i18n/(.*)\.json$  /app/i18n/$1.json [L]
RewriteRule ^(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf|csv)$      /adminApp/$1.$2 [L]
# Doesn't look like you need this rule
RewriteRule ^rest/(.*) /rest/$1 [L]
RewriteRule ^img/(.*)  /adminApp/img/$1 [L]
RewriteRule ^(.*)      /adminApp/index.html [L]