Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite, script alias

         

immasavagebeast

12:30 pm on Oct 5, 2011 (gmt 0)

10+ Year Member



I have an issue with creating my rewrite for this cgi script query string. I'm using mod_alias/scriptalias to point incoming users to run a script. If a user browses to: "http://www.example.com/example1/cgi-bin/script.cgi?b_action=xts.run&m=portal/main.xts&startwel=yes" it runs a script an produces an ugly URL: http://www.example.com. Basically, I want to strip out the entire URI and query string so users only see a pretty URL: http://www.example.com/reporting. Below is some of my configuration.

#File called example1.conf - contains mod_alias directives
ScriptAlias /example1/cgi-bin /opt/path/to/dir/cgi-bin/
Alias /example1 /opt/path/to/dir/cgi-bin/

<Directory "/opt/path/to/dir/cgi-bin/">
Options Indexes MultiViews
AllowOverride All
</Directory>

#http.conf - section that has the mod_rewrite which I know is awful #and wrong so I'm trying to fix it

RewriteEngine On
RewriteCond $1 !ex2.html
RewriteCond $1 !ex3.xml
RewriteCond $1 !ibmcognos
# Comment out line below and replace HOSTNAME with DNS host entry
RewriteRule ^(.*)$ http://www.example.com [R,L]


Any help will be greatly appreciated. Thank you

lucy24

6:06 am on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Key sentence, with added line breaks but otherwise unchanged:

If a user browses to:

http://www.example.com/example1/cgi-bin/script.cgi?b_action=xts.run&m=portal/main.xts&startwel=yes

it runs a script an produces an ugly URL:

http://www.example.com

Basically, I want to strip out the entire URI and query string so users only see a pretty URL:

http://www.example.com/reporting


OK, so we've got three things: The link the user originally clicked; the "real" location they're going to; and the text that you want to have displayed in the menu bar. Which is which? What's that bare "example.com" line in the middle?

The redirect-plus-rewrite combination is the Hot Question of the Hour. Skim the last page or two of threads in this forum and you'll find that at least a quarter of them are concerned with the same question.

And all of them contain dire admonitions from g1smd about the perils of combining mod_alias and mod_rewrite.

# Comment out line below and replace HOSTNAME with DNS host entry

Awright, come clean. Where did you get the code?

immasavagebeast

6:14 pm on Oct 6, 2011 (gmt 0)

10+ Year Member



I just started a job here and one of my first tasks is to clean this mess up. So I have no idea where the previous admin got this.

If you type into a browser address bar: http://www.example.com then server side you are redirected to run the cgi script and it the browser address bar it shows:
http://www.example.com/example1/cgi-bin/script.cgi?b_action=xts.run&m=portal/main.xts&startwel=yes

What I want to do is when the user types into the address bar:
http://www.example.com then I want it to run the server side script but display in the address bar http://www.example.com/reporting

wilderness

6:31 pm on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your htaccess will NOT over-ride your PHP or cgi-script.

You need to correct the URL outputs first and then attempt your rewrites, based upon requests coming from other websites (outside your own).

The URL's and the server paths are two entirely different issues, however you must understand and utilize both.

There's a corresponding thread which provides searching the archives for:

"QUERY_STRING" + "[R=301,L]"

immasavagebeast

1:44 pm on Oct 7, 2011 (gmt 0)

10+ Year Member



I'm not trying to override the scriptalias because I know it can't because of the order of operations in which apache processes mod_alias and mod_rewrite. I want to just rewrite what the cgi-script is showing in the URL bar. Therefore it's just a rewrite and not a redirect.

immasavagebeast

3:38 pm on Oct 7, 2011 (gmt 0)

10+ Year Member



Through more reading plus trial and error. I'm just basically looking to mask what shows to the end user in the URL bar.

lucy24

6:38 pm on Oct 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's both a redirect and a rewrite. You first need a redirect to send the user to the "real" location where all the query stuff will execute. And then you need a rewrite to give the user a pretty address. This, in turn, means you have to do everything within the same module, because this is the only way you can be absolutely certain it will execute in the correct order.

[edited by: lucy24 at 7:33 pm (utc) on Oct 7, 2011]

immasavagebeast

7:22 pm on Oct 7, 2011 (gmt 0)

10+ Year Member



Lucy, Thanks. That's the exact conclusion I came to. So basically I have to do everything in mod_rewrite. I can't keep the scriptalias redirect then use mod_rewrite to rewrite the URL. Thanks!