开发者

Hiding file name with htaccess

My 开发者_如何学编程Perl app reveals the filename 'processing.cgi' in the addressbar when running on my hosting account, but on localhost it seems to work fine, that is, it doesn't reveal the filename 'processing.cgi'.

Here's .htaccess thats exactly the same on both locations:

AddHandler cgi-script .cgi
Options +ExecCGI 

IndexIgnore *
DirectoryIndex processing.cgi

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ processing.cgi/$1

RewriteRule ^$ processing.cgi [L]
RewriteRule ^/$ processing.cgi [L]

This is the .htaccess in /public_html:

Options -Indexes 

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.main-domain\.com$ [NC]
RewriteRule ^(.*)$ http://main-domain\.com/$1 [R=301,L]

# BEGIN WordPress
# <IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteBase /
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.php [L]
# </IfModule>

# END WordPress

What do I need to change?

Many thanks for your help!


With current setup, if you type http://example.com/ in your browser location bar there is no possible way you can see processing.cgi in such location bar unless your Perl script performs an HTTP redirection (by sending the Location header). So I suggest you double-check your Perl code.

Whatever, I see what appear to be many directives scattered random around the file. I think it'll be more productive if I explain what they mean:

AddHandler cgi-script .cgi
Options +ExecCGI 

Enable CGI scripts and map the *.cgi extension so any file that ends with .cgi is considered a program.

IndexIgnore *

Instruct Apache to generate empty directory listings. When people do not want directory listings, they normally just disable them: Options -Indexes

DirectoryIndex processing.cgi

When the URL points to a directory, find and display a file called processing.cgi in such directory. Are you planning to maintain a copy of your Perl program on every directory of your site?

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

If the URL doesn't map to an existing file or directory...

RewriteRule ^(.*)$ processing.cgi/$1

When user types http://example.com/foo/bar.jpg actually run http://example.com/processing.cgi/foo/bar.jpg. See if any other rules matches.

RewriteRule ^$ processing.cgi [L]

When user types http://example.com actually run http://example.com/processing.cgi. We're done with rules.

RewriteRule ^/$ processing.cgi [L]

When user types http://example.com/ actually run http://example.com/processing.cgi. We're done with rules.

It's clear now that you have a lot of redundant rules. Your exact needs are not 100% clear to me but I guess you can savely remove most of your directives:

AddHandler cgi-script .cgi
Options +ExecCGI

Options -Indexes

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ processing.cgi/$1 [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜