I have a problem with some pages urls. The pages url structure is like this:


I want that when i acces the url from above to redirect me to:


In /wp/ is wordpress installed. I tried this in .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteCond %{query_string} ^token=12345
RewriteRule (.*) /$1? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]

but it redirects me to:


Any ideas?

Later edit:

/wp/ - the folder where Wordpress is installed;

/custom-taxonomy/ - a custom taxonomy, like /partners/ where i enter all my partners

/somepagename - a dynamic page, like /xyz-ltd, /abcd... dynamic pages created for the custom taxonomy.

I can not put a rule for every page, would need a general rule to remove the query string.

  • i think its your Rewritebase conflicting with the condition and final rule. Sorry ive been too heavy on IIS these days to provide a real answer – Brandt Solovij Dec 7 '15 at 5:22

You can use add_rewrite_rule in WordPress to capture the query args or add_rewrite_endpoint. If you really just want to redirect based on certain rules then template_redirect can be a good place to use a header redirect.

| improve this answer | |
  • Was this helpful at all? – jgraup Dec 11 '15 at 11:33

Use this in your .htaccess-

Redirect 301 /slug/somepagename/?token=12345 http://www.example.com/wp/slug/somepagename/
| improve this answer | |

I think the problem is in your permalink configuration. It seems that WP redirects




anyway. If you solve this, probably by setting your permalinks in wp admin, then the redirect will work.

It's funny but I'm doing the exact same thing right now for my site, redirecting mobile queries (?m=1) to the main pages. So I can confirm that your code is correct. The only thing different I do is add $ at the end of the query, like ^token=12345$, but I don't think this makes a difference.

| improve this answer | |
  • I am using custom permalink - /%postname%/. I just added more information about my problem in the question section.. i think the main problem is that i installed wordpress in a folder from domain(example.com/wp), not in the root of the domain.. Also i entered by mistake the /slug/ part, it's a custom taxonomy there, if it helps this information. The token is used for custom acces permission, like in your case for redirecting mobile queries. I tried to add $ but didn't do anything. – Crys Dec 7 '15 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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