0

My oroginal url looks like this

http://www.example.com/showads.php?type=1

And this rewrite seems to work

RewriteRule ^listings/type/([0-9]+)/?$ showads.php?adtype=$1 [NC,L]

So that all I have to do is type www.example.com/listings/type/1 and it goes to the original url

My problems comes when I add one more parameter to the original url like this

http://www.example.com/showads.php?type=1&clearfilters

I have tried several combinations of rewrites but none of them work.

The last one I have before giving up was this

RewriteRule ^listings/type/([0-9]+)/clear?$ showads.php?type=$1&clearfilters [NC,L]

What am I doing wrong? in that last rewrite? Your help is appreciated.

Thanks

JT

Better Explanation

Thanks for the reply. However,that still does not work.

Let me try to explain what happens

If I were to type this url

http://www.example.com/showads.php?adtype=3&clearfilters

I get the expected results. And here is an explanation of it's use

A user clicks on various links on the site and each link sets a different session variable. Over the span of a few clicks there could be 5 or 6 session variables set.

If one was to submit this url without the clearfilters

http://www.example.com/showads.php?adtype=3

You would be setting a session variable for adtype to 3

So now we would have the adtype session variable and possibly a few other set

When you submit this url with the clearfilters set

http://www.example.com/showads.php?adtype=3&clearfilters

The page unsets all the existing session variables and sets only the adtype session to 3.

Having said that, I am looking for a rule where i could just clean up the url and type something like:

http://www.example.com/listings/type/3/clear 

to do the same as the ugly url.

Maybe there is a better way. I am all ears.

Thanks

JT

  • `However,that still does not work` - Please explain. After adding the RewriteRules (given in my answer), does it reach showads.php? For debugging, add `print_r($_GET)` at the top of `showads.php`. What are you seeing? – kums Oct 23 '14 at 02:44

1 Answers1

0

It is not clear from your question if you want the same replacement URL regardless of whether you have or not have the /clear part of the URL.

If you want the same replacement URL with or without /clear, you can use this:

RewriteEngine On
RewriteRule ^listings/type/([0-9]+)(/clear)?$ showads.php?type=$1&clearfilters [NC,L]

If you want the clearfilters parameter in the replacement URL only when the typed URL has the /clear part, you can do this:

RewriteEngine On
RewriteRule ^listings/type/([0-9]+)$        showads.php?type=$1 [NC,L]
RewriteRule ^listings/type/([0-9]+)/clear$  showads.php?type=$1&clearfilters [NC,L]
kums
  • 2,661
  • 2
  • 13
  • 16