【问题标题】:match query string variables with mod_rewrite?将查询字符串变量与 mod_rewrite 匹配?
【发布时间】:2014-06-20 17:01:44
【问题描述】:

我正在尝试使用的网站是http://northidahocvma.org/2GD/index.php?page=1

所以假设我的 URL 带有如下查询字符串参数:

/index.php?page=1

使用 mod_rewrite,我如何将它们重定向到这样的 URL?

/page/1/1/

我得到了这个代码,但仍然无法弄清楚

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L]

RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]

【问题讨论】:

    标签: .htaccess mod-rewrite query-string


    【解决方案1】:

    将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+index\.php\?page=([^\s&]+) [NC]
    RewriteRule ^ /page/%1? [R=302,L]
    
    RewriteRule ^page/([^/.]+)/?$ /index.php?page=$1 [L,QSA,NC]
    

    【讨论】:

    • 我输入northidahocvma.org/2GD/index/1 还是northidahocvma.org/2GD/index/page/1 我都试过了,他们将我引导到错误页面或northidahocvma.org/index/page/1
    • 您将在浏览器中输入:http://example.com/page/1 将被重写为http://example.com/index.php?page=1
    • 我得到的只是一个白页,左上角有一个单词错误
    • 你能在 firebug 中检查你得到 404 的 URL 吗?
    • 首先确保通过在.htaccess 顶部放置相同的垃圾(随机)文本来启用此 .htaccess 并查看它是否会生成 500(内部服务器)错误?
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    相关资源
    最近更新 更多