【问题标题】:URL rewrite using Apache使用 Apache 重写 URL
【发布时间】:2015-08-06 13:05:26
【问题描述】:

我有一个托管在 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 或在用户位于 http://www.example.com/abc 时刷新浏览器时,才会发生这种重定向

“abc”可以是任意字符串。

【问题讨论】:

  • mod_rewrite 不知道复制粘贴或刷新等用户操作

标签: apache copy-paste url-redirection


【解决方案1】:

我在 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-10
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多