htaccess从旧网址重定向到新网址 [英] htaccess redirect from old url to new url

查看:65
本文介绍了htaccess从旧网址重定向到新网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从htaccess中的旧网址重定向到新网址,这是我的代码/尝试/尝试,没有任何运气.

I am trying to redirect from old url to new url in htaccess and here is my code/try/attempts without any luck.

旧网址- https://www.rosterelf.com/blog/why-i-always-hire-for-attitude-over-skill-通常

新网址- https://www.rosterelf.com/blog/why-i-always-hire-attitude-over-skill-usually

.htaccess 代码尝试1

RedirectMatch 301 ^/blog/为什么我总是会在技术上占主导地位,/blog/为什么总是会在技术上在态度占主导地位

我还有另外301个重定向,但即使我评论了这些重定向,上述条件也不起作用,因此请相信其他条件没有错.

I have couple of other 301 redirects but even if I comment those, above condition does not work so believe others conditions are not in fault.

这是我完整的 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]
    RedirectMatch 301 ^/blog/why-i-always-hire-for-attitude-over-skill-usually /blog/why-i-always-hire-attitude-over-skill-usually

    ##
    ## 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>

有人可以指导我该怎么做.

Can someone guide me what should I do to achieve this.

谢谢

推荐答案

根据您显示的示例,可以请尝试以下操作.

Based on your shown samples, could you please try following.

<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 - [NC,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]
RewriteRule ^blog/why-i-always-hire-for-attitude-over-skill-usually /blog/why-i-always-hire-attitude-over-skill-usually [R=301,NC,L]

##
## Black listed folders
##
RewriteRule ^(?:bootstrap|config|vendor|storage/(?:cms|logs|framework|temp/protected|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>

这篇关于htaccess从旧网址重定向到新网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆