【发布时间】: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