apache - Htaccess 301 博客重定向网址
问题描述
我已经在我的实时网站上进行了 301 次重定向,例如从这个 urlhttps://www.rosterelf.com/support-detail/1424/how-can-i-copy-shifts-from-a-day-to-another
到这个 url https://www.rosterelf.com/support-detail/how-can-i-copy-shifts-from-a-day-to-another
,并且按照我的预期工作正常。这是我如何使它工作的 .htaccess 代码。
RewriteRule ^(support-detail)/\d+/([\w-]+)/?$ /$1/$2 [R=301,NC,L]
现在我想为我想要重定向的博客再添加一个条件。
比如说,我有这个https://www.rosterelf.com/blog-detail/2211/how-to-create-a-winning-team
我想重定向到的url,https://www.rosterelf.com/blog/how-to-create-a-winning-team
因此我把代码放在下面,但不幸的是它对我不起作用。
RewriteRule ^(blog-detail)/\d+/([\w-]+)/?$ /blog/$1/$2 [R=301,NC,L]
这就是我的 .htaccess 文件的样子。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /
##
## Uncomment following lines to force HTTPS.
##
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{SERVER_NAME}/$1 [L,R=301]
##
## Allow robots.txt
##
RewriteRule ^robots.txt - [L]
## 301 redirect for old support details page url to new one
## OLD URL https://www.rosterelf.com/support-detail/1903/how-can-employees-clock-inout-of-time-clock-different-slug
## NEW URL https://www.rosterelf.com/support-detail/how-can-employees-clock-inout-of-time-clock-different-slug
RewriteRule ^(support-detail)/\d+/([\w-]+)/?$ /$1/$2 [R=301,NC,L]
RewriteRule ^blog-detail/\d+/([\w-]+)/?$ /blog/$1 [R=301,NC,L]
##
## Black listed folders
##
RewriteRule ^bootstrap/.* index.php [L,NC]
RewriteRule ^config/.* index.php [L,NC]
RewriteRule ^vendor/.* index.php [L,NC]
RewriteRule ^storage/cms/.* index.php [L,NC]
RewriteRule ^storage/logs/.* index.php [L,NC]
RewriteRule ^storage/framework/.* index.php [L,NC]
RewriteRule ^storage/temp/protected/.* index.php [L,NC]
RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]
##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/public/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/resized/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
##
## Standard routes
##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
有人可以指导我如何解决这个问题吗?
谢谢
解决方案
您可以有 2 个单独的重定向规则,如下所示:
RewriteRule ^(support-detail)/\d+/([\w-]+)/?$ /$1/$2 [R=301,NC,L]
RewriteRule ^blog-detail/\d+/([\w-]+)/?$ /blog/$1 [R=301,NC,L]
确保完全清除浏览器缓存并将这些规则保留在 .htaccess 的顶部
顺便说一句,您可以将多个Black listed folders
规则合并为一个:
##
## Black listed folders
##
RewriteRule ^(?:bootstrap|config|vendor|storage/(?:cms|logs|framework|temp/protected|app/uploads/protected))/ index.php [L,NC]
推荐阅读
- macos - 如何在不关闭 SIP 的情况下在 macOS Catalina 上生成编译数据库?
- python - 如何运行 TensorArray 操作?
- algorithm - Leet代码:强盗,使用递归+备忘录
- android - 如何将我的 Firebase 数据库坐标传递给 onMapReady?
- android - Dagger 2:多模块项目,注入依赖但在运行时得到“lateinit property repository has not been initialize”错误
- spring-boot - 影响RequestMapping处理的顺序
- python - 如何在列表派生类中使用列表推导
- python - 如何更改 tkinter 中选项卡的实际背景而不是选项卡标题的背景
- python-3.x - 碰撞检测后运动停止 - Pygame
- python - 您如何添加来自多个条目的用户输入,并将它们添加在一起