URL 使用 Apache 重写

URL rewrite using Apache

我在 Apache 中托管了一个应用程序 http://www.example.com

DocumentRoot 设置为 /var/www/html/myapp

现在,我想写一个规则,如果有人触发 URL http://www.example.com/abc, 它应该重定向到 http://www.example.com

棘手的部分是,只有当用户直接复制粘贴时才会发生这种重定向http://www.example.com/abc or refresh the browser when the user is in http://www.example.com/abc

"abc" 可以是任何字符串。

我通过 httpd.conf

的以下添加得到了这个
<VirtualHost *:80>
     ServerName www.example.com

     DocumentRoot /var/www/html/abc

     <Directory /var/www/html/abc>
         RewriteEngine on

         # Don't rewrite files or directories
         RewriteCond %{REQUEST_FILENAME} -f [OR]
         RewriteCond %{REQUEST_FILENAME} -d
         RewriteRule ^ - [L]

         # Rewrite everything else to index.html to allow html5 state links
         RewriteRule ^ index.html [L]
     </Directory>
 </VirtualHost>