【问题标题】:How to create Generic RewriteRule for slash separated url parameters in htaccess?如何在 htaccess 中为斜线分隔的 url 参数创建 Generic RewriteRule?
【发布时间】:2017-04-18 20:19:10
【问题描述】:

我想从 url 获取我的数据,女巫是这样用斜线分隔的:

www.example.com/page.php/12

女巫必须解释为:

www.example.com/page.php?id=12

我不会在我的 .htaccess 中指定像“page.php”这样的页面名称,它必须是像“*.php”这样的通用名称。 我使用这条线,但这改变了我的 baseUrl 和我的 css 无法访问:

RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)$  $1.php?id=$2

【问题讨论】:

  • 您不需要重写规则,因为您可以在代码中使用$_SERVER["PATH_INFO"] 来获得相同的/12

标签: apache .htaccess


【解决方案1】:

参见RewriteCond to skip rule if file or directory exists:您应该添加条件以不将请求重定向到现有文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/([^/]+)$  $1.php?id=$2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 2011-05-03
    • 2010-11-25
    • 2013-01-29
    相关资源
    最近更新 更多