【问题标题】:Looking to rewrite a url with a hash using htaccess希望使用 htaccess 重写带有哈希的 url
【发布时间】:2012-01-11 22:12:14
【问题描述】:

我有一个格式为http://www.site.com/index.php/page 的网址,想将其重写为http://www.site.com/#/page,但我似乎无法在任何地方找到答案。有人可以帮忙吗?

【问题讨论】:

    标签: .htaccess url hash rewrite


    【解决方案1】:

    如果你只是想用# 替换index.php,你可以这样做:

    RewriteRule   ^/index.php/(.*)    /#/$1  [NE,R]
    

    NE 标志应该防止 mod_rewrite 转义 #

    【讨论】:

    • 在 .htaccess 上下文中使用此规则时,您需要删除前导 /。所以RewriteRule ^/index.php/(.*) /#/$1 [NE,R]。感谢 M_M 展示了 NE 的用例。很有教育意义。
    • 感谢您的提示,但我无法正常工作。我有其他 RewriteRules 并且它们都工作正常,所以文件应该没有问题。这是完整的代码。 AddType text/cache-manifest .appcache RewriteEngine on RewriteCond %{HTTPS} (on)? RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC] RewriteCond %{REQUEST_URI} (.+) RewriteRule .? http(?%1s)://www.%2%3 [R=301,L] RewriteRule ^/index.php/(.*) /#/$1 [NE,R]
    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    相关资源
    最近更新 更多