WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i'm trying to achieve the following:

user enters this URL into browser


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:


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]


in my functions.php i add a filter for request

add_filter('request', 'request_it');
function request_it($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?

share|improve this question
i just found out about the [R] flag for RewriteRule but 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
up vote 1 down vote accepted

i fixed it using the apache proxy module:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} !location
RewriteRule ^(boston|newyork)/$ /index.php?location=$1 [NC,QSA,P]

RewriteCond %{QUERY_STRING} !location
RewriteRule ^(boston|newyork)/(.*)$ /$2?location=$1 [NC,QSA,P]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


the [P] option does the trick.

share|improve this answer

I am on similar turf. See: flexible rewrite 'ramble' URLs with Wordpress And no, [R] or 301 redirects won't get you there. And any regular htaccess rewrite causes trouble, because some part of WPstill helps himself to the original REQUEST_URI (or maybe PATH_INFO).

Did you notice, that you can override $_SERVER variables? (even if that screams hacking)

echo "server".$_SERVER['REQUEST_URI']; //get's you: the original thing
$_SERVER['REQUEST_URI'] = 'banana';
echo "server".$_SERVER['REQUEST_URI']; //gets you: banana

If you figure out something, please post it.

share|improve this answer
i did find a solution - posted it as an answer below. – pkyeck Apr 11 '12 at 22:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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