简体   繁体   中英

Htaccess 301 redirect url not working as per expectation

I want to match url in htaccess and want 301 redirect based on the url check. But its not working properly as per my expectations.

Here is what I want to achieve and here is my code try.

MY OLD URL - https://www.mywebsite.com/support-detail/1903/my-title

MY NEW URL TO REDIRECT 301 - https://www.mywebsite.com/support-detail/my-title

.htaccess

RedirectMatch 301 /support-detail/$1/$2 /support-detail/$2

As you can see my code, I want all the pages which has something like this, /support-detail/$1/$2 , I want theme to redirect at /support-detail/$2 but its keep saying 404 page not found.. I even try with /support-detail/$1 but its still not working..

Can someone guide me what I am doing wrong here in my url.

Any guidance will be highly appreciated.

Thanks

With your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM