【问题标题】:Redirect root to another folder but anything else to app router将根目录重定向到另一个文件夹,但将其他任何内容重定向到应用路由器
【发布时间】:2017-03-06 09:47:20
【问题描述】:

不确定我想要的是否可以完成,我发现这里有很多很接近的东西,但不完全在那里。我想要/需要将根 URL (/) 重定向到在它自己的 web 根目录中的子文件夹中运行的 wordpress 站点。使用:

RewriteEngine on
# our root gets redirected to wordpress
RedirectMatch ^/$ http://mysubdomain.com

...效果很好。然后对于除根以外的任何东西(例如 example.com/somepath),我需要根中的 index.html 来处理它。这是带有自己的路由器的 Vue JS 应用程序的入口点。我试过了:

RewriteEngine on
# our root gets redirected to wordpress
RedirectMatch ^/$ http://mysubdomain.com
# anything else load our app (index.html in the web root)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://example.com/$1 [L,QSA]

...但这会导致 Bowser 中出现过多的重定向错误。我试过了:

RewriteEngine on
# our root gets redirected to wordpress
RedirectMatch ^/$ http://mysubdomain.com
# anything else load our app (index.html in the web root)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.html [L,QSA]

... 这几乎可以工作,除了路径中有一个文字 index.html ,而不仅仅是 urls 路径。目标是让根路径通过 web 根目录中的 hte Vue JS 应用程序(我认为是通过 index.html)进入该文字路径。因此,如果访问http://example.com/somepath,浏览器位置应该是通过 Vue JS 路由器的路径进程。

希望这是有道理的。有什么想法或想法吗?我也知道我可以重定向到其中包含 Vue JS 应用程序的子文件夹,但这不是客户想要的,除非该子文件夹可以从 URL 中排除。

TIA!

【问题讨论】:

    标签: javascript apache .htaccess


    【解决方案1】:

    我们选择使用 Vue JS 应用程序路由器进行重定向,以便根 url (/) 执行 JS 重定向,而不是尝试通过 .htaccess 进行重定向。问题已解决。

    【讨论】:

      猜你喜欢
      • 2016-06-27
      • 1970-01-01
      • 2018-04-17
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 2021-09-03
      • 2011-01-19
      相关资源
      最近更新 更多