我有一个要转换为新cms的网站。这样做的原因是不会丢失入站链接,并且不会在搜索引擎中导致死页。
在旧网站中,URL的结构如下:
website.com/4212/write-a-google-review
和新的:
website.com/blog?write-a-google-review
尽管我有一定的灵活性,可以像以下任何一种方式将ID添加到URL字符串中:
website.com/blog?4212&write-a-google-review
website.com/blog?4212-write-a-google-review
website.com/blog?4212/write-a-google-review
website.com/blog?write-a-google-review&4212
我尝试了许多重写变体,其中一些仅与ID匹配,另一些与文本字符串匹配,但是还没有找到正确的公式。
RewriteRule ^4212/?$ blog?4212/write-a-google-review [NC,L] ##
RewriteRule ^[4212]?$ blog?4212/write-a-google-review [NC,L] ##
评论添加了对第一个答案的测试(作者Croises)。
作为一个单一的重定向,我发现这是可行的,但前提是我提供了https://www.mywebsite.com/的完整网址:
RewriteRule write-a-google-review/?$ https://www.mywebsite.com/blog?write-a-google-review [NC,L]
当我添加以下两行时,导致页面损坏,没有样式,没有帖子内容输出:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+(?:/.+?)?)/?$ blog?$1 [L]
很好奇,我将其更改为包含完整的URL,如下所示,它用作所有条目的正则表达式解决方案:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+(?:/.+?)?)/?$ http://www.mywebsite.com/blog?$1 [L]
答案 0 :(得分:1)
您可以使用:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+(?:/.+?)?)/?$ blog?$1 [R=301,QSA,L]
答案 1 :(得分:0)
RewriteCond %{QUERY_STRING} (^|&)blog\?4212($|&)
RewriteCond %{QUERY_STRING} (^|&)write-a-google-review($|&)
RewriteRule ^website\.com/index\.php$ /website.com/blog?4212-write-a-google-review&%{QUERY_STRING}
website.com/index.php?blog?4212&write-a-google-review
website.com/blog?4212-write-a-google-review
RewriteRule ^([a-z]+)/([0-9]+)/([a-z0-9\-]+)?$ index.php?alias=$1\?$2\-$3 [L]
Array
(
[alias] => blog?8753-lowering-expectations-with-skype
)