【发布时间】:2019-01-02 12:07:31
【问题描述】:
我正在尝试实现类似的网址
example.com/path1 到 example.com/index.php?p1=path1
example.com/path1/path2 到 example.com/index.php?p1=path1&p2=path2
在我的 .htaccess 中,我有:
RewriteEngine On
RewriteRule ^(.*)/(.*)$ /index.php?c=$1&g=$2 [NC,L]
RewriteRule ^([a-zA-Z0-9-_]+)$ /index.php?g=$1 [NC,L]
它适用于 example.com/path1/path2 但适用于 example.com/path1 的情况> 仅当 url 中没有点时才有效。例如,我想将 example.com/mydomain.com 工作到 example.com/index.php?g=domain.com 但我无法使其工作。
你能帮我解决这个问题吗?
【问题讨论】:
-
与
([a-zA-Z0-9-_]+)您明确地只处理字母数字加下划线的情况。这将排除您的示例案例。
标签: .htaccess mod-rewrite