Need a quick review - RewriteRule

Hello All!

I think I now understand the basics of mod_rewrite and I just completed the following rule:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/shop/index\.php\ HTTP/ [NC]
RewriteCond %{SERVER_PORT} ^8080$
RewriteCond %{QUERY_STRING} ^name=abc$
RewriteRule ^.*index\.php$ h2tp:// [R=301,L]

So what I am doing is:

  1. Check THE_REQUEST - does it contain uri like /shop/index.php HTTP
  2. Is the port 8080
  3. Does it contain a query string ?name=abc
  4. Does the uri contain /index.php

If all above YES then the url will be as above.

Couple of questions:

  1. Since my app goes through Siteminder I am not able to interpret the behaviour right away since there is authetication required first
  2. In the RewriteRule line, does Apache automatically append the query String or should one write the new url the way I have.

Would greatly appreciate feedback.



Sorry - maybe the caption of my post was a bit misleading.
I have included the new rule and restarted Apache but the rule does not appear to be working. Since Siteminder comes into play for authentication I am not sure if there is something going on there. Before I talk to the Siteminder folks I was wondering if someone could look at the receipe I have written and let me know if I have missed anything. Thanks a lot for your help.

When testing a rule and finding it doesn’t work I always debug by taking things out. For example, I would try here to take out the RewriteConds, or at least the ones you’re not sure about.

The block looks fine to me btw, although I would use %{REQUEST_URI} instead of %{THE_REQUEST} because the latter is very buggy.

Also, if you want to know if something contains index.php, why do you use ^.*index\.php$ ?

Oh, and I take it Apache accepts the connections on port 8080 and will thus be able to perform this rewrite you want?

I’m not following your first question, could you restate that please?

Regarding the second question, I’m pretty sure Apache copies the query string if you don’t supply anything in the RewriteRule, but you can easily test that :slight_smile:

Thanks ScallioXTX for your response.

We already have one rule that works but that uri is without query string.
The new rule that I am working in is to include the query string.

Re my first question - what I wanted to say was that between the apache server and the application server we have an authentication check (done by Siteminder). I don’t have immediate access to logs which can tell how Siteminder handled the new url. Once I am confident that my rule looks good, I can go to the administrator and review the logs.

After reading further re query strings I am now clear that Apache will include them.

I have noted yor comment re changing THE_REQUEST to REQUEST_URI.

Re your question <<if you want to know if something contains index.php, why do you use ^.index\.php$>>
This is because there will be a string (domain name, port) in front of index.php so I included a .
for that purpose. What is the alternative?


I have never worked with siteminder or a similar setup so I’m afraid I can’t be of much help in that regard.

The alternative is to drop the start anchor ( ^ ) and just use index\\.php$, which is just “anything that ends in (because of the $) index.php” :slight_smile: