我最近将网站从原始PHP迁移到了WordPress CMS平台。更改的一件事是帖子的URL格式。
原来的URL格式为/news-and-views/{id}/{slug}
,如下所示:
https://newable.co.uk/news-and-views/840433571/award-winning-exporters.php
此实际网址为https://newable.co.uk/news-and-views/article.php?Id=840433571&title=award-winning-exporters
我使用了以下重写规则:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(news-and-views)/([0-9]+)/([^/]+).php /$1/article.php?Id=$2&title=$3 [L]
新的URL格式为/ {slug},如下所示:
https://newable.co.uk/award-winning-exporters/
所以我写了这样的新规则:
RewriteRule ^(news-and-views)/([0-9]+)/([^/]+).php /$3 [L]
我也测试过。
但是,通过Twitter单击文章仍会带我到以下URL:
https://newable.co.uk/news-views/840433571/award-winning-exporters.php
这是重定向的完整列表
<IfModule mod_rewrite.c>
# Turn on Rewrite Engine
RewriteEngine On
RewriteRule ^(news-and-views)/([0-9]+)/([^/]+).php /$3 [L]
# Lending redirects
Redirect 301 /lending/ https://newable.co.uk/money/business-loans
Redirect 301 /lending/business-finance/ https://newable.co.uk/money/business-loans
Redirect 301 /lending/business-finance/product-details.php https://newable.co.uk/money/business-loans
Redirect 301 /lending/business-finance/how-it-works.php https://newable.co.uk/money/business-loans
Redirect 301 /lending/business-finance/introducers.php https://lending.newable.com/register
Redirect 301 /lending/business-finance/mentoring.php https://newable.co.uk/money/business-loans
# Private Investing redirects
Redirect 301 /private-investing/ https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/entrepreneurs/ https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/entrepreneurs/apply-for-funding.php https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/partners.php https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/about-us.php https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/press/ https://newable.co.uk/money/eis-investment
Redirect 301 /private-investing/events/ https://events.newable.co.uk/
# International Trade redirects
Redirect 301 /international-trade/ https://newable.co.uk/advice/supporting-exporters
Redirect 301 /international-trade/export-engine.php https://newable.co.uk/advice/supporting-exporters
Redirect 301 /international-trade/department-for-international-trade.php https://newable.co.uk/advice/supporting-exporters
Redirect 301 /international-trade/erdf.php https://newable.co.uk/advice/supporting-exporters
# Business Advice redirects
Redirect 301 /business-advice/ https://newable.co.uk/advice
Redirect 301 /business-advice/growth-services.php https://newable.co.uk/advice/innovation
Redirect 301 /business-advice/social-impact-programmes.php https://newable.co.uk/advice/social-impact
Redirect 301 /business-advice/ready-to-supply.php https://newable.co.uk/advice/social-impact
Redirect 301 /business-advice/events.php https://events.newable.co.uk
Redirect 301 /business-advice/support.php https://newable.co.uk/advice/social-impact
Redirect 301 /business-advice/partners.php https://newable.co.uk/advice
Redirect 301 /business-advice/erdf-projects/global-growth.php https://newable.co.uk/advice/supporting-exporters
Redirect 301 /business-advice/erdf-projects/casts.php https://newable.co.uk/advice
Redirect 301 /business-advice/get-exporting-kent-and-east-sussex.php https://newable.co.uk/advice
Redirect 301 /business-advice/erdf-projects/asean.php https://newable.co.uk/advice
Redirect 301 /business-advice/erdf-projects/south-east-international-business-growth.php https://newable.co.uk/advice
# Space redirects
Redirect 301 /space.php https://newable.co.uk/space
# Property redirect
Redirect 301 /property.php https://newable.co.uk/space
# Digital redirect
Redirect 301 /digital.php https://newable.co.uk
# America Made Easy
Redirect 301 /AmericaMadeEasy https://newable.co.uk/advice/america-made-easy/
# Generic redirects
Redirect 301 /faqs.php https://newable.co.uk/faq
Redirect 301 /team.php https://newable.co.uk/team
Redirect 301 /locations.php https://newable.co.uk/locations
Redirect 301 /reports https://newable.co.uk/downloads
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress