3

I'm trying to do a redirect with a .htaccess file matching these specific requirement:

  1. The page/script name is foo.php
  2. The querystring must contain p=1
  3. There could be any number of other querystring variables present

If these conditions are met, you should be redirected to: /new-url/

This is what I've come up with that doesn't work. It matches and redirects /foo.php but not /foo.php?p=1 or /foo.php?p=1&x=5

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} ^foo\.php$ [NC]
RewriteCond %{QUERY_STRING} (^|&)p=1(&|$) [NC]
RewriteRule . new-url/? [R=301,L]

Thanks very much in advance for any assistance!

1 Answer 1

1

Can you try:

RewriteCond %{QUERY_STRING} (^|&)p=1(&|$) [NC]
RewriteRule (^|/)foo\.php$ /new-url/? [R=301,L,NC]

Also test it in a different browser to avoid browser caching issues due to R=301

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.