Page rules with wordpress permalinks

page-rules

#1

Hi there! I am not quite sure how these page links work. I want

https://hostup.org/blog/(date here)/*
to redirect to:
https://hostup.org/blog/$1

so for an example.
/blog/2019/02/02/how-to-secure-a-ubuntu-linux-server-in-3-simple-steps/
redirects to
/blog/how-to-secure-a-ubuntu-linux-server-in-3-simple-steps/

How can I make it remove the date?


#2

You can try the following but I wouldnt be surprised if it didnt work

hostup.org/blog/*/*/*/*

If that doesnt work you would probably have to look into workers. I’d suggest doing it server-side though.


#3

Yeah this is what I tried at first but it did not work :confused:

I guess I could always try something like this on the nginx server

RedirectMatch 301 ^/blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+)/$ https://hostup.org/$4

#4

I just tried it with a demo page rule and it should actually work. Post a screenshot of your page rule.


#5


#6

In that case you will take the year. You want to refer to the fourth asterisk which is $4 then.


#7

Woops


#8

Okay I changed it. Although it might take some time to update

https://hostup.org/blog/2019/02/02/how-to-secure-a-ubuntu-linux-server-in-3-simple-steps/ NOPE
https://hostup.org/blog/2019/02/02/how-to-secure-a-ubuntu-linux-server-in-3-simple-steps works :smiley:


#10

That is probably because of the trailing slash. You might need another page rule but I cant guarantee that you will get this to work. Server-side is probably still the best choice.


#12

rewrite “/blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)” https://hostup.org/blog/$5 permanent; from - https://yoast.com/change-wordpress-permalink-structure/ I believe this will work for nginx rewrite. I will just try this instead when I get home :smiley: Thank you for the help anyways!


#13

You can try Redirection, an excellent free plugin with which you can set your regular expression redirects. It allows you to write redirects to your .htaccess file.

The formula /*/*/*/*/, even if it worked with or without the trailing slash, could be problematic, as WordPress generates all kinds of archive and paginated pages that might result in something like:

example.com/category/category-name/page/3/ being redirected to
example.com/3/ and that would be a 404!