apache - 具有 RewriteRule 和别名 Apache 的 VirtualHost 无法正常工作
问题描述
<VirtualHost *:80>
ServerName abc.example.com
ServerAlias abc.example.com
DocumentRoot /var/www/html/abc
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} !^/adl/$
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
</VirtualHost>
alias /adl /opt/dl
我有一个像这样的虚拟主机设置,它工作得很好。现在我想如果路径中有/adl不应该应用重写规则,并且我有一个别名指向我的机器目录结构中的路径。
解决方案
我已经按照下面的方式修复了它
<VirtualHost *:80>
ServerName walton2.biz-motion.com
ServerAlias walton2.biz-motion.com
DocumentRoot /var/www/html/fmcg
RewriteEngine On
RewriteRule ^/?(adl)($|/) - [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html
</VirtualHost>
发布它是因为如果有人面对这个。