【问题标题】:redirect users from dynamic to static url (with two parameters)将用户从动态 url 重定向到静态 url(带有两个参数)
【发布时间】:2014-02-17 09:17:21
【问题描述】:

我的网站上有一个网址,其结构如下:
- mywebsite.com/directory/object.php?id=[id]&title=[title]
使用 .htaccess 文件,我已将上述动态 URL 更改为以下内容:
- mywebsite.com/directory/[id]/[title] 类似于 stackoverflow 的这个问题的 URL..

我想知道如何将任何输入旧动态 URL 的用户重定向到新的静态 URL。我知道你使用 RewriteCond,但我不知道代码。

将动态 URL 更改为静态 URL 的我的 .htaccess 文件代码包含:

    RewriteEngine On
    RewriteRule ^directory/([^/]*)/([^/]*)$ /directory/object.php?id=$1&title=$2 [L]

提前致谢!

【问题讨论】:

    标签: php apache .htaccess url mod-rewrite


    【解决方案1】:

    这样吧:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+(directory)/object\.php\?id=([^&]+)&title=([^\s&]+) [NC]
    RewriteRule ^ /%1/%2/%3? [R=301,L]
    
    RewriteRule ^directory/([^/]+)/([^/]+)/?$ /directory/object.php?id=$1&title=$2 [L,QSA]
    

    【讨论】:

    • 工作愉快!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    相关资源
    最近更新 更多