regex - 301 将旧网址重定向到移动网站中的新网址

标签 regex .htaccess url-redirection

我需要将旧网址重定向到位于 http://www.domain.com/mobile/ 的移动版网站中的 seoed 网址,并且有自己的 .htaccess 文件具有以下重写规则:

RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1

RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3

我如何 301 将旧网址重定向到新网址?

最佳答案

这样说:

RewriteEngine On
RewriteBase /mobile/

RewriteCond %{THE_REQUEST} /category\.php\?cat=([^\s&]+)\s [NC]
RewriteRule ^ browse-%1-videos.html? [R=302,L,NE]

RewriteRule ^browse-(.*)-videos.html$ category.php?cat=$1 [L,QSA,NC]

RewriteRule ^browse-(.*)-videos-([0-9]+)-(.*).html$ category.php?cat=$1&page=$2&sortby=$3 [L,QSA,NC]

关于regex - 301 将旧网址重定向到移动网站中的新网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301181/

相关文章:

javascript - 如何在 PHP 中将页面重定向到不带井号 (#) 的 URL?

php - 使用 PHP 在 WordPress 中使用国家代码动态重写子文件夹

nginx - 如何在NGINX中获取URL的子域

regex - 如何在 Notepad++ 中将带连字符的单词与正则表达式合并?

php - 使用多域托管防止直接访问主域上的网站

python - 查找另一个字符串后面的第一个匹配项,python regex multiline

laravel - 使用 Redirect::to() 重定向到另一个网站

php - 使用不同的参数处理 .htaccess 重定向?

ruby - 如何在 Ruby 中查找字符串中特殊字符之间的文本值?

RegEx:带有尾随和前导空格的所有行