【问题标题】:.htaccess url parameter rewrite for specific page.htaccess url 参数重写特定页面
【发布时间】:2017-07-18 20:57:15
【问题描述】:

我已经奋斗了几个小时,搜索了谷歌和 StackOverflow,没有解决我的问题,希望你们能提供帮助! :-)

我有一个页面,参数如下:profile?userid=123456789。我希望它重写为profile/123456789。这个我有,但现在这个页面上的所有链接都得到/profile/link。有什么解决办法吗?提前致谢,我的 .htaccess 代码来了。

RewriteEngine on
RewriteCond %{REQUEST_URI} !/profile\.php

RewriteRule ^profile/([^/]*)$ /profile?userid=$1 [L,QSA]

【问题讨论】:

    标签: apache .htaccess mod-rewrite web


    【解决方案1】:

    试试这个,它适用于许多配置

    RewriteEngine On
    RewriteRule ^profile/([^/]*)$ /profile?id=$1 [L]
    

    如果您希望([^/]*) 是唯一的数字,您需要使用 PHP 来重写您的网址

    【讨论】:

      【解决方案2】:

      您可以如下更改规则参数顺序以使其正常工作

      RewriteEngine on
      RewriteRule ^profile?userid=([^/]*)$ profile/$1 [L]
      

      希望对你有帮助:)

      【讨论】:

      • 需要把参数倒过来
      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多