我有一个应用程序,可以使用下面显示的虚拟主机配置在我的本地wamp服务器上正常运行。我最近购买了共享主机,但与我的localhost不同,我无法访问Apache的httpd-vhost.conf
,而是必须操纵站点根目录.htaccess
以便正确地“连接”我的应用程序。
问题是我不知道如何使用RewriteEngine
来编写RewriteRules
,可以模拟(在某种程度上)这个虚拟主机配置:
<VirtualHost *:80>
ServerName sitename
ServerAdmin webmaster@localhost
DocumentRoot "c:/wamp/www/siteroot"
AliasMatch /(.*)\.(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 /rest/(.*) "c:/wamp/www/siteroot/rest/$1"
AliasMatch /img/(.*) "c:/wamp/www/siteroot/app/img/$1"
AliasMatch /(.*) "c:/wamp/www/siteroot/app/index.php"
ErrorLog "logs/sitename_app_error.log"
LogLevel warn
CustomLog "logs/sitename_app_access.log combined" %a
</VirtualHost>
<VirtualHost *:80>
ServerName admin.sitename
ServerAdmin webmaster@localhost
DocumentRoot "c:/wamp/www/siteroot"
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"
ErrorLog "logs/sitename_app_error.log"
LogLevel warn
CustomLog "logs/sitename_app_access.log combined" %a
</VirtualHost>
<Directory "c:/wamp/www/siteroot">
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "c:/wamp/www/siteroot/app">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory "c:/wamp/www/siteroot/adminApp">
AuthName "Login required"
AuthType Basic
AuthUserFile "c:/wamp/www/siteroot/adminApp/.htpasswd"
AuthGroupFile "/dev/null"
Require valid-user
</Directory>
<Directory "c:/wamp/www/siteroot/rest">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
*请注意sitename
和siteroot
不是网站/文件路径的实际名称。
aliasMatches是我的网站“工作”最重要的。这就是为什么我认为我可以使用.htaccess
中的RewriteRules。
即使你不熟悉RewriteRules,如果你能告诉我正则表达式的意思,那也会有很大的帮助!任何帮助表示赞赏!