我的网站上有一个 URL,其结构为:
- mywebsite.com/directory/object.php?id=[id]&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]
提前致谢!
最佳答案
这样吧:
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]
关于php - 将用户从动态网址重定向到静态网址(带有两个参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21365536/