【问题标题】:mod_rewrite - rewrite directory to query string except /#!/mod_rewrite - 重写目录以查询字符串,除了 /#!/
【发布时间】:2014-11-10 13:38:19
【问题描述】:

我正在尝试将 www.domain.com/something/some/ 重写为 www.domain.com/index.php?q=something/some/

这是我目前所拥有的:

RewriteCond %{REQUEST_FILENAME} ([a-z-]+)/?$
RewriteRule (.*) index.php?q=$1 [QSA,L]

但我想排除以下网址: www.domain.com/#!/something

你能帮忙吗?

谢谢, 约翰

【问题讨论】:

  • # 和之后的所有内容都不应该到达您的服务器,因为它是一个片段标识符,不应该附加到请求中。

标签: php apache .htaccess mod-rewrite


【解决方案1】:

您可以在 root .htaccess 中使用此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?q=$1 [QSA,L]

使用.+ 也可以处理/#!/something,因为在# 没有到达网络服务器之后,Apache 只会得到/ 作为文本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    相关资源
    最近更新 更多