skip to Main Content

I have done 301 redirects on my live site something like from this url https://www.rosterelf.com/support-detail/1424/how-can-i-copy-shifts-from-a-day-to-another to this url https://www.rosterelf.com/support-detail/how-can-i-copy-shifts-from-a-day-to-another and its working fine as per my expectations. Here is my .htaccess code how I made it work.

RewriteRule ^(support-detail)/d+/([w-]+)/?$  /$1/$2 [R=301,NC,L]

Now I want to add one more condition for my blog which I want to redirect.

Say for example , I have this url https://www.rosterelf.com/blog-detail/2211/how-to-create-a-winning-team which I want to redirect to https://www.rosterelf.com/blog/how-to-create-a-winning-team and hence I put below code but unfortunately its not working for me.

RewriteRule ^(blog-detail)/d+/([w-]+)/?$  /blog/$1/$2 [R=301,NC,L]

This is how my .htaccess file looks like.

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

Can someone guide me how can I resolve this ?

Thanks

2

Answers


  1. You can have 2 separate redirect rules like this:

    RewriteRule ^(support-detail)/d+/([w-]+)/?$ /$1/$2 [R=301,NC,L]
    
    RewriteRule ^blog-detail/d+/([w-]+)/?$ /blog/$1 [R=301,NC,L]
    

    Make sure you completely clear your browser cache and keep these rules at top of your .htaccess

    btw you can combine multiple Black listed folders rules into one:

    ##
    ## Black listed folders
    ##
    RewriteRule ^(?:bootstrap|config|vendor|storage/(?:cms|logs|framework|temp/protected|app/uploads/protected))/ index.php [L,NC]
    
    Login or Signup to reply.
  2. With your shown samples, could you please try following. Added few more fixes to your htaccess file along with new rules.

    Please make sure to clear your browser cache before testing your URLs.

    <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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search