Setting a redirect for a article number to a static PHP page. RewriteCond %{QUERY_STRING}

6 posts by 2 authors in: Forums > CMS Builder
Last Post: March 28, 2014   (RSS)

Setting a redirect for a article number to a static PHP page.

By drewh01 - March 12, 2014 - edited: March 12, 2014

Trying to get one of these example options to work. Can anyone with more experience help me with this?

RewriteCond %{QUERY_STRING}  ^p=375$

RewriteRule (.*)  http://www.example.org/content/MyNewPage?  [R=301,L]

---

RewriteCond %{QUERY_STRING} ^route=product/category&path=35&page=([0-9]+)$

RewriteRule ^index\.php$ /product/category/35/page_%1? [R=301,L]

---

RewriteCond %{QUERY_STRING}   ^sInstance=1&EventID=139$ 

RewriteRule ^event_book\.asp$ /clean-landing-url/ [NC,R=301,L]

Hi d,

I've done some local testing and this htaccess rule should work:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^10-12$
RewriteRule ^/?festivalsDetail\.php$ http://chambermusicsedona.org/sedona-jazzfest.php [L,R=301]

So if the URL is:

http://chambermusicsedona.org/festivalsDetail.php?10-12

It should redirect the user to:

http://chambermusicsedona.org/sedona-jazzfest.php

Another option is to use this CMS Builder function:

redirectBrowserToUrl('http://chambermusicsedona.org/sedona-jazzfest.php');

Then wrap an if statement around this function so that only redirects the user if they have loaded record 12.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By drewh01 - March 26, 2014

Thanks!

When using the first option, the record number gets attached to the end of the URL during the FWD:

http://chambermusicsedona.org/sedona-jazzfest.php?10-12

Any way to have the "?10-12" removed during the redirect?

:-)

Hi Drew,

Weirdly, if you don't pass variables across in the URL, it includes the variables of the page you're redirecting from. But if you pass a variable in the redirect URL, it doesn't.

So you can solve this issue by adding a question mark to the end of you're redirect URL:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^10-12$
RewriteRule ^/?festivalsDetail\.php$ http://chambermusicsedona.org/sedona-jazzfest.php? [L,R=301]

The question mark will make the htaccess think there are already variables on the new URL, and so it won't pass the ones from the old URL.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By drewh01 - March 28, 2014

Oooooo - that's pretty awesome right there!

Thanks!!!