漂亮的 RewriteRule 回到旧格式

Pretty RewriteRule back to old format

我有一些由 Google 索引的旧网址,格式为 https://example.com/1234/name-of-page 因为我不再使用这些 RewriteRules,所以我想将它们重新路由到 https://example.com?id=1234&name=name-of-page

如何使用 .htaccess 执行此操作?

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]


RewriteRule ^([^/]*)/(.*)/?$ https://%{HTTP_HOST}/title.php?id=&name= [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^sitemap\.xml/?$ sitemap.php

如果您正在寻找专门重写从 1234/name-of-page 开始的 uri,请尝试以下操作。请确保在测试您的 URL 之前清除浏览器缓存。

RewriteEngine ON
RewriteRule ^(1234)/(name-of-page)/?$ title.php?id=&name= [L]

您可以尝试遵循更通用的规则。请确保您一次仅在 .htaccess 文件中尝试以上或以下规则。

RewriteEngine ON
RewriteRule ^([^/]*)/(.*)/?$ title.php?id=&name= [L]