custom url rewrite

Your rewriterule should be: add_rewrite_rule(‘^directory/view/(.+)/(\d+)/’, ‘index.php?pagename=directory/view&search=$matches[1]&number=$matches[2]’, ‘top’); Remember to flush your rewriterules after every edit (go to settings > permalinks). EDIT added complete code example. function add_directory_rewrite() { add_rewrite_tag(“%search%”, ‘(.+)’); add_rewrite_tag(“%number%”, ‘(\d+)’); add_rewrite_rule(‘^directory/view/(.+)/(\d+)’, ‘index.php?pagename=directory/view&search=$matches[1]&number=$matches[2]’, ‘top’); } add_action( ‘init’, ‘add_directory_rewrite’ ); In page.php for testing purposes: <?php echo get_query_var(“search”); echo get_query_var(“number”); ?> This worked on my … Read more

Author Profile URL

To change all author URLs one would normally change the author base, however, since you want multiple author bases, we’ll have to do things a bit differently. There are two parts to this – The first part is getting WordPress to recognize incoming requests for your custom author pages and route them properly. To do … Read more

External/non-WP rewrite rule without QSA

The apache rewrite flags like QSA are hard coded, see source. Not sure why it would bother you, but if you really want to change it, then you can and should use the mod_rewrite_rules hook for that. Below an example on how to do it: add_filter( ‘mod_rewrite_rules’, ‘wpse107528_change_mod_rewrite_rules’ ); function wpse107528_change_mod_rewrite_rules( $rules ) { $pattern … Read more

Multiple Permalinks for Same Post

The request parsing is handled in WP::parse_request(). After that, there’s a action hook parse_request which gives you the instance of the wp object. We assume that http://www.example.com/my-custom-post-type/this-is-a-cool-article is your permalink and http://www.example.com/mon-type-de-poste-personnalise/cest-un-article-sympa ends up in a 404. So the first thing to check in your callback should be, if the wp object is in a … Read more

WordPress rewrite rules for state and city

Wasn’t as hard as I thought. Here’s the working example, in case anyone finds it helpful: function em_query_vars($vars) { array_push($vars, ‘state’); array_push($vars, ‘city’); return $vars; } add_filter(‘query_vars’,’em_query_vars’); function em_rewrite() { add_rewrite_rule( ‘^state/([^/]*)/([^/]*)/?’, ‘index.php?state=$matches[1]&city=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘^state/([^/]*)/?’, ‘index.php?state=$matches[1]’, ‘top’ ); add_rewrite_tag(‘%state%’,'([^&]+)’); add_rewrite_tag(‘%city%’,'([^&]+)’); } add_action(‘init’, ’em_rewrite’); function em_templates($template) { global $wp_query; if (isset($wp_query->query_vars[‘state’]) && isset($wp_query->query_vars[‘city’])) { … Read more

Change Query String to pretty permalink

Try this rewrite rule in your functions.php function string_url_rewrite() { global $wp_rewrite; add_rewrite_tag(‘%pet-page%’, ‘([^&]+)’); //In the rewrite rule you need to enter page slug and page id add_rewrite_rule(‘^Enter_Page_slug/([0-9]+)/?’, ‘index.php?page_id=Enter_Page_ID&pet-page=$matches[1]’, ‘top’); $wp_rewrite->flush_rules(true); } add_action(‘init’, ‘string_url_rewrite’, 10, 0); Now you also need to change the format of URL in anchor tag. For example, your previous URL http://www.example.com/my-account/view-pet/?pet-page=2 … Read more

htaccess: Remove trailing slash from URL ending with .xml/ only

If you’re outputting a sitemap, there’s no reason to wait for the query for your page- which is what is producing the redirect. Hook an earlier action and you won’t need anything to counter the trailing slash, because it won’t happen- EDIT Here’s a complete version with registering query vars, rules, and parse_request action: // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)