I’d suggest you use RedirectMatch instead of RewriteRule, assuming your server has mod-alias installed. Most do.
If you use WP rewrites, I believe the destination has to be a file, usually index.php. Let’s say the page ID of where-to-eat-drink is 123. The destination could be 'index.php?page_id=123&var=$matches[1]'
Any time you change WP rewrites, you must visit the permalinks settings page or call flush_rewrite_rules(). You should not call the flush function in regular code that executes on each request. It should be added to rare or one time code like a plugin activation hook. Thus when developing your code, visiting the permalinks screen is easier.
]]>www.mywebsite.com/admin/where-to-eat-drink/raj_pavilion
now correctly redirects to
www.mywebsite.com/admin/where-to-eat-drink/
using the function below
full wp function:
function custom_rewrite_rule() {
add_rewrite_rule('^where-to-eat-drink/([^/]+)/?','index.php?page_id=54&var=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
Call to provide me with ‘raj_pavilion’ to query database is
$_GET['var']
however this returns nothing.
]]>Some redirects through .htaccess will strip query strings from the URL. Be sure the rewritten URL with query string (index.php?page_id=54&var=raj_pavilion) is not being redirected further. Check your access logs to see possible additional redirects.
If neither of those help, we will need to dig deeper. How and where are you trying to use $_GET[‘var’]?
]]>In functions.php :
function filter__query_vars( $query_vars ) {
$query_vars[] = 'place';
return $query_vars;
}
add_filter( 'query_vars', 'filter__query_vars' );
Then in the document I could reference it by
echo $place
Changing variable names for better reference is an excellent reason! Otherwise you may revisit this code a year later and think “what the heck is this “var” for?”
]]>