Forum Moderators: phranque

Message Too Old, No Replies

Is it not possible to redirect cgi-sys pages?

         

therealgtron

2:18 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



i'm sure my syntax is incorrect now but i tried it several while troubleshooting and this was the last one i tried.

none of them seemed to work so any help would be great :)

RewriteEngine on
RedirectCon %{REQUEST_URI} ^Count.cgi ¦ FormMailclone.cgi ¦ FormMail.cgi ¦ FormMail.pl ¦ addalink.cgi ¦ cgiecho ¦ cgiemail ¦ countedit.cgi ¦ domainredirect.cgi ¦ entropybanner.cgi ¦ entropybanner.cgiwrap ¦ entropysearch.cgi ¦ formmail.cgi ¦ formmail.pl ¦ guestbook.cgi ¦ helpdesk.cgi ¦ mchat.cgi ¦ randhtml.cgi ¦ randhtml.cgiwrap ¦ realhelpdesk.cgi ¦ realsignup.cgi ¦ scgiwrap ¦ signup.cgi)$
RewriteRule ^(.*)$ %{HTTP_HOST}%/nowhere.no

thanks in advance

jdMorgan

3:14 pm on Aug 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why not try something simpler, rather than starting with such a complex rule?

First see if mod_rewrite works. In example.com/.htaccess, try:


RewriteEngine on
#
RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

Request example.com/foo.html from your server, and you should land at google

Note: If you're not putting your code in a .htaccess file (you didn't say), then add a leading slash to the RewriteRule pattern, making it "^/foo\.html$". This applies to RewriteRule patterns only.

If that doesn't work, then you may need to add a line:


[b]Options +FollowSymLinks[/b]
RewriteEngine on
#
RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

If the first rule above doesn't work, but you get a server error from adding this new Options line, then you cannot use mod_rewrite on this server as it is currently configured -- talk to your host.

If it does work, then try a simpler version of your desired rule, using either just the RewriteEngine directive, or also adding the Options directive -- whichever worked above:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/Count\.cgi$ [NC]
RewriteRule . http://%{HTTP_HOST}/nowhere.no [R=301,L]

If that works, then add some more URIs to your list:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/(Count\.cgi¦FormMailclone\.cgi¦FormMail\.cgi)$ [NC]
RewriteRule . http://%{HTTP_HOST}/nowhere.no [R=301,L]

Important: Change the broken pipe "¦" characters above to solid pipe characters before use; Posting on this forum modifies the pipe characters.

You may also wish to consider using an internal rewrite, rather than an external redirect. This avoids telling the (presumably-malicious) client what just happened. Instead of sending a redirect response to the client, it simply serves the alternate content from "/nowhere.no" -- without telling the client that the malicious request was detected:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/(Count\.cgi¦FormMailclone\.cgi¦FormMail\.cgi)$ [NC]
RewriteRule . /nowhere.no [L]

Another alternative is to simply return a 403-Forbidden response to the client, and be done with it:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/(Count\.cgi¦FormMailclone\.cgi¦FormMail\.cgi)$ [NC]
RewriteRule . - [F]

I noted many syntax errors, and I noticed that you had misspelled "RewriteCond," added spaces here and there, and did not escape the literal periods in your pattern.

Be warned that mod_rewrite is not a high-level programming language; It does not allow you to enter your code "free-style." You must follow the documented syntax exactly, or risk taking your server down and/or ruining the rankings of your pages in search. I strongly recommend that you refer to the Apache mod_rewrite documentation [httpd.apache.org] while coding, rather than trying to use examples found in forums... even this one.

There are some other useful documents cited in our Apache Forum Charter as well (see links at top of this page).

Jim

therealgtron

3:38 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



thanks for your reply!

RewriteEngine is on and i can rewrite pages just not the ones listed above in the alias cgi-sys directory.

i couldnt even get this to work:
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{REQUEST_URI} ^/Count\.cgi$ [NC]
RewriteRule . [%{HTTP_HOST}...] [R=301,L]

there's extra spaces and stuff because i did a find and replace to remove some of the garbage from my desperate and even more ugly attempts. lol that was just an ugly sample of what i was trying to do.

jdMorgan

4:16 pm on Aug 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where are you placing this code?

therealgtron

4:20 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



i'm testing it in .htaccess but after i get it to work i will move it to a .conf

jdMorgan

5:22 pm on Aug 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please be specific. If the .htaccess file is not located in the physical filepath (not URL-path, and not rewritten-filepath) to the Alias target directory, then it will not be executed -- The Alias directive will take precedence, and your code will never run for those requests.

This is one of the implications of the statement repeated in the documentation that ".htaccess is a per-directory configuration file.

Jim

therealgtron

5:43 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



sorry for the lack of info.

currently i have:
Options +FollowSymLinks
RewriteEngine on

RewriteCond ^/Count\.cgi$ [NC]
RewriteRule . /nowhere.no [L]

in .htaccess which is in root web directory (public_html)

i am trying to redirect /cgi-sys/Count.cgi to page not found and as fast and invisible as possible.

thanks again for your help.

jdMorgan

6:17 pm on Aug 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, if /cgi-sys/ is Aliased in httpd.conf, your code will not run unless you place it in an .htaccess file in the directory to which /cgi-sys/ is aliased, or put the code into httpd.conf. In either case you may need to adjust the pattern and/or URL-paths to suit the new location. It is not clear to me whether /cgi-sys/ is the actual path to the cgi directory or if it is the Alias path to that directory.

The code you just posted is still invalid because the RewriteCond is missing an argument. Please review the RewriteCond I posted previously above.

Jim

therealgtron

7:56 pm on Aug 15, 2008 (gmt 0)

10+ Year Member



thanks again for your help.