Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache Htaccess 301博客重定向url_Apache_.htaccess_Redirect_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache Htaccess 301博客重定向url

Apache Htaccess 301博客重定向url,apache,.htaccess,redirect,mod-rewrite,url-rewriting,Apache,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我在我的现场站点上做了301重定向,类似于这个urlhttps://www.rosterelf.com/support-detail/1424/how-can-i-copy-shifts-from-a-day-to-another 指向此urlhttps://www.rosterelf.com/support-detail/how-can-i-copy-shifts-from-a-day-to-another 按照我的期望,它工作得很好。这是我的.htaccess代码,我是如何使它工作的 Rew

我在我的现场站点上做了301重定向,类似于这个urlhttps://www.rosterelf.com/support-detail/1424/how-can-i-copy-shifts-from-a-day-to-another 指向此urlhttps://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]
现在我想为我的博客添加一个条件,我想重定向它

比如说,我有这个urlhttps://www.rosterelf.com/blog-detail/2211/how-to-create-a-winning-team 我想重定向到它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>
有人能指导我如何解决这个问题吗


谢谢

您可以有两个单独的重定向规则,如下所示:

重写规则^support detail/\d+/[\w-]+/?$/$1/$2[R=301,NC,L] 重写规则^blog detail/\d+/[\w-]+/?$/blog/$1[R=301,NC,L] 确保完全清除浏览器缓存,并将这些规则保留在.htaccess的顶部

顺便说一句,您可以将多个黑名单文件夹规则合并为一个:

##
## Black listed folders
##
RewriteRule ^(?:bootstrap|config|vendor|storage/(?:cms|logs|framework|temp/protected|app/uploads/protected))/ index.php [L,NC]

有了你们展示的样品,你们能试一下下面的吗。在htaccess文件中添加了更多的修复程序和新规则

请确保在测试URL之前清除浏览器缓存

<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}%{REQUEST_URI} [NE,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]


##
## 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
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

</IfModule>

请确认这是否是htaccess文件中仅有的两条规则?或者你还有其他规则?只是想确保我们有这里显示的所有规则,否则可能会影响其他事情,谢谢。我只有这2条规则//这是我的.htaccess文件,请您在您的问题中发布它们,很抱歉链接没有为我打开,鼓励您将所有细节发布到问题本身中,谢谢。好的,让我把整个代码放进去。@RavinderSingh13看起来anubhava的解决方案对我很有效。。谢谢你的支持。你的解决方案对我很有效。。非常感谢你,谢谢你。。我会更新。谢谢