Remap URLs from Relative to Absolute

WP CLI is a great tool for performing common admin and maintenance tasks on a WordPress install. It has a large range of commands that among other things allow you to install plugins, regenerate thumbnails, and in your case, perform a search and replace on the database. When migrating from dev to production I’d normally … Read more

Use WordPress’ URL rewrite engine

I suggest you don’t try to take out the WP_Rewrite class and re-use it in your application, but look at other frameworks instead. Many MVC frameworks have nice rewrite engines, that not only offer more flexibility in handling incoming URLs, but also generating internal links according to these formats. The WordPress rewrite system is tightly … Read more

Nginx rewrite rules

The correct Nginx rewrite rules for WordPress are: location / { try_files $uri $uri/ /index.php?q=$uri&$args; } This sends everything through index.php and keeps the appended query string intact. If your running PHP-FPM you should also add this before your fastcgi_params as a security measure: location ~ \.php { try_files $uri =404; // fastcgi_param …. // … Read more

open all .docs in word online

I’m not sure this question is WordPress-related. It sounds like it might be handled via .htaccess redirect, or a browser extension. That said: you could try to use the wp_get_attachment_url filter, that is applied to the URL returned by wp_get_attachment_url(). For example: function wpse95271_filter_wp_get_attachment_url( $url ) { if ( 0 === stripos( strrev( $url ), … Read more

Prevent /wp-admin/ from redirecting to homepage?

In my case, it ended up being some kind of adverse interaction in the nginx wordpress config that I had. Something about not passing along the naked arguments: location / { original line: try_files $uri @php; new line: try_files $uri $uri/ /index.php?$args; } And the associated upstream was wrong. Used the config suggested here: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ … Read more

How to properly rewrite url by custom var

So, first off, never flush rewrite rules on every page load. Better to do it on plugin activation one time. Step 1: add the rewrite rule: add_action( ‘init’, ‘wpse26555_add_rewrite’ ); function wpse26555_add_rewrite() { // You should probably rewrite to index.php instead of shop.php? add_rewrite_rule( ‘/shop/brand/([^/]+)/?$’, ‘index.php?brand=$matches[1]’, ‘top’ ); } Step 2: add the query var … Read more