i'm trying to achieve the following:
user enters this URL into browser
http://mydomain.com/boston/categoryname/postname/
i then want to get the first "folder" and check whether or not it's "boston" or "newyork" - if yes, then remove this part of the URL, add it as an query-parameter and pass the modified URL on to wordpress:
http://mydomain.com/categoryname/postname/?location=boston
i tried this using apache's mod_rewrite like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(boston|newyork)/(.*)$ /$2?location=$1 [NC,QSA,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
in my functions.php i add a filter for request
add_filter('request', 'request_it');
function request_it($query_vars)
{
print_r($query_vars);
}
it echos
Array (
[page] =>
[name] => postname
[category_name] => boston/categoryname
[location] => boston
)
so the location gets passed on as a query-parameter but the REQUEST_URI is still /boston/categoryname/postname/ instead of /categoryname/postname/ and wordpress tries to display the wrong content.
how can i really strip the location from the URL?
is mod_rewrite not the right thing to use?
is there a function where WP evaluates the URLs that are passed to it where i can hook into and look for my location?
[R]flag forRewriteRulebut this really redirects the user and changes the look of the url (http://himbeer/asdasdasd/?location=berlin) - not what i wanted ... :( – pkyeck Jan 24 '12 at 15:52