【问题标题】:Rewrite get parameter with .htaccess?用.htaccess 重写get 参数?
【发布时间】:2014-10-02 15:07:18
【问题描述】:

我想要一个类似的 htaccess 网址

mysite.com/category/1

mysite.com/category.php?cat=1

我的 htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

有一个简单的想法? 谢谢你:-)

【问题讨论】:

  • 有什么问题?

标签: php .htaccess url get rewrite


【解决方案1】:

您没有捕获正确的信息(您应该将名称与数字分开)并且您没有添加查询变量:

RewriteRule ^([^\.]+)$ $1.php [NC,L]

应该是这样的:

RewriteRule ^(\w+)/(\d+)$ $1.php?cat=$2 [NC,L]
                   ^^^^^ capture the number
             ^^^^^ capture the name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多