1

Is there a way to add a pattern of redirects to wordpress from a plugin? I'm using a host that sets up wordpress for me and doesn't give me access to the file system, so I can't edit the .htaccess file.

I've found lots of plugins that allow you to list URLs that you want to redirect, but I haven't found any that let you insert patterns based on regular expressions.

Specifically, I have an "events calendar" plugin installed that had a page of events for each day (whether or not that day actually had any events). A later release of that plugin, took those pages away. Now they are all 404, when I would like to redirect them to the main events page. They are all of the format:

  • /events/2017-08-29/
  • /events/2017-08-23/
  • /events/2017-08-19/
  • ... (thousands more)

How do I put in a single redirect rule for all of them?

3
  • Does "pretty permalinks" feature of WP can be enabled / work in your environment at all?
    – Rarst
    Oct 17 '13 at 12:54
  • if you cann't change the htaccess how are you will be posible to implement code that "create redirection" ? you able to change (edit) code of you theme? add any custom plugin? any mu plugin? opt-in? any code injection posible? or even is it posible any plugin install? Oct 17 '13 at 12:54
  • I can use "pretty permalinks" -- I currently have the permalinks format set to "Post name". I can also install plugins through the wordpress interface. But I don't have any other access to the file system (like shell login, or ftp). Oct 17 '13 at 13:09
1

Oleg's comment made me think that I might be able to find a plugin that would allow me to edit the .htaccess file.

I installed the WP htaccess editor plugin. and was able to edit the .htaccess file despite not having shell or ftp access to the file system. I insterted the following line at the beginning of the htaccess file:

RedirectMatch 301 ^/events/[0-9]{4}-[0-9]{2}-[0-9]{2}/$ http://example.com/events/upcoming/

Now my pages are redirecting properly instead of showing 404 status.

3
  • There is an easier way to do the rewrites. You can just use add_rewrite_rule function to alter the rewrites. Please read the entire codex page to learn a proper usage, especially the "IMPORTANT" sections.
    – Dero
    Oct 17 '13 at 13:44
  • Wouldn't that API be geared towards plugin developers? I have never written my own WordPress plugin before. Oct 17 '13 at 13:48
  • Sorry, I didn't realize you don't have access to the filesystem. You could perhaps use the WordPress theme editor to alter your functions.php and make just a small change using the function I mentioned, but if you found a plug-in that works for you, you'll probably want to stick with it.
    – Dero
    Oct 17 '13 at 13:54

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.