1

I have a URL like this:

example.com/blog/page/5

I want to change it to:

example.com/blog/page-5

I tried using a RewriteRule like this:

RewriteRule ^blog/page-([0-9]+) /blog/page/$1

but this returns 404 page not found. After a lot of debugging I realized that the reason it returns 404 is that the $_SERVER['REQUEST_URI'] in PHP stays blog/page-5 even after Apache rewrites it to blog/page/5.

It is possible to do it with redirection by adding [R] at the end of the RewriteRule but it will change the URL in browser to /blog/page/5, and I don't want that.

Any ideas?

  • "...the reason it returns 404 is that..." - The directive you posted is malformed and won't actually do anything, which is why you are are getting a 404 in this instance - apart from the other reason you mentioned. However, this isn't something you can do in .htaccess. You need to actually modify the URL that WordPress generates for pagination - within WordPress itself. You might then use .htaccess to redirect the old URL for the benefit of SEO (but this isn't a functional requirement). – MrWhite Nov 26 '19 at 13:16
  • 1
    @MrWhite Yeah I wrote the directive from the top of my head so I messed it up. I edited it now. Any idea how modify theURL that WordPress generates for pagination? – Marko Nov 26 '19 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.