【问题标题】:.htaccess PHP rewrite link.htaccess PHP 重写链接
【发布时间】:2014-03-11 10:12:32
【问题描述】:

我有问题,不知道如何解决。 我有这样的网址: http://somedomain.com/link.php?lnk=1&sid=dsds

并需要将其更改为:

http://somedomain.com/link/1/dsds

如果只有一个变量我用这个:

RewriteEngine on RewriteRule ^link/([a-zA-Z0-9_-]+)$ link.php?lnk=$1

但我不知道如何附加第二个变量 &sid={something}

提前感谢您的帮助。

【问题讨论】:

  • 您检查过许多重复项中的任何一个吗? -->
  • 是的,我的问题没有找到任何答案
  • @MichałBereszyński, **RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)$ index.php ?p=$1&sp=$2 [L] **

标签: php html .htaccess


【解决方案1】:
 RewriteEngine on 
 RewriteRule ^link/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ link.php?lnk=$1&sid=$2

【讨论】:

    【解决方案2】:

    如果第一个参数/值只使用数字,那么你可以使用

    RewriteEngine On    
    RewriteRule ^link/([0-9]+)/([a-zA-Z0-9_-]+)$ link.php?lnk=$1&sid=$2 [L]
    

    Apache mod_rewrite Introduction(参见“正则表达式反向引用可用性”部分中的“图 1”)

    RewriteRule Flags

    【讨论】:

      【解决方案3】:

      试试这个:

      RewriteEngine on 
      RewriteCond %{QUERY_STRING} ^lnk=(.+)\&sid=(.+)
      RewriteRule ^link\.php link/%1/%2/?  [R=301,L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        相关资源
        最近更新 更多