【问题标题】:.htaccess redirect all to subfolder.htaccess 将所有重定向到子文件夹
【发布时间】:2014-02-24 15:35:37
【问题描述】:

我有这个网站,比如http://example.com/。我希望所有请求都重定向(用户必须在他的地址栏中看到 url)到http://example.com/#!/the_requested_page

所以这就是我想要发生的事情:

  • 请求http://example.com/ => 显示http://example.com/
  • 请求http://example.com/somepage => 显示http://example.com/#!/somepage
  • 请求http://example.com/#!/somepage => 显示http://example.com/#!/somepage

如何使用 .htaccess 文件做到这一点?

我试过这个,但它没有执行上面列表的第二部分。

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/#!/

# Don't apply to URLs that go to existing files or folders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /#!/$1 [L]

如果我请求http://example.com/somepage,它会在地址栏中显示,但网站会显示主页 (http://example.com)。

除此之外,这不会重定向,而只是重写...

希望你能帮帮我。

【问题讨论】:

    标签: .htaccess mod-rewrite redirect rewrite


    【解决方案1】:

    摆脱第一个条件。 URL 的# 部分从未发送到服务器,因此您无法匹配它。然后把规则改成这样:

    RewriteRule ^(.+)$ /#!/$1 [L,R,NE]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2020-06-07
      • 2014-06-17
      • 2012-11-23
      相关资源
      最近更新 更多