0

I want to Rewrite my url using .htaccess file using php as I got hundreds of url's like this and I don't want to add individual RewriteRule for these many url's.

I want to remove numbers from start of url and replace with specific url like below examples

For example 1,

I want to replace this url: https://www.example.com/2023/03/03/5-abc-blog-name-or-url/

To this: https://www.example.com/blog/5-abc-blog-name-or-url/

For example 2,

I want to replace this url: https://www.example.com/2022/04/01/abc-xyz-blog-name-or-url-235/

To this: https://www.example.com/blog/abc-xyz-blog-name-or-url-235/

Please help me with this.

Thank you so much in advance.

I have tried this but this isn't working for me

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$/ /blog/$ [L]
ADyson
  • 57,178
  • 14
  • 51
  • 63
SIHala
  • 11
  • 2
  • `^([0-9]+)$/` makes little sense. This would demand that the _whole_ URL path, from start to finish, would consist only of digits. `$` anchors the pattern at the end of the subject string you are testing - so an `/` "after the end", also makes very little sense. And neither does `$` in the substitution URL. – CBroe Sep 01 '23 at 10:22
  • can you give me RewriteRule that matches my request because current one is not working @CBroe – SIHala Sep 01 '23 at 10:59
  • `RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*) /$1 [R=301,L]` But we really rather expect a bit more effort from people here, than just going "make for me", so please keep that in mind the next time you ask a question. – CBroe Sep 01 '23 at 11:16
  • @CBroe i did tried this with my knowledge after you answer before RedirectMatch /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /blog/$4 – SIHala Sep 01 '23 at 11:24

0 Answers0