Link to home
Start Free TrialLog in
Avatar of kesea
kesea

asked on

map a URL to an HTML file

Is there a way to map a URL, say mysite.com/HANDLEGOESHERE, to pull up mysite.com/members/HANDLEGOESHERE.html when it's accessed?  How would this be done?  I am guessing by configuring Apache Web Server but I'm not sure.  What is the best way to handle if this feature would be accessed A LOT?
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kesea
kesea

ASKER

Doesn't seem to be working.  Thought at first that the last line (to disable HTTP Trace) might have been overwriting the previous rule but even when I commented out it doesn't work.  Keep getting "File does not exist" for C:/Apache2/htdocs/HANDLEGOESHERE when I am sure there is a valid html file at C:/Apache2/htdocs/members/HANDLEGOESHERE.html

<VirtualHost *:80>
LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>
RewriteEngine on
RewriteRule ^/([^./]+)$ /members/$1.html [L]

# use mod_rewrite.so to disable HTTP Trace
RewriteCond %(REQUEST_METHOD) ^TRACE
#RewriteRule .* - [F]
Avatar of kesea

ASKER

Hmm even this simple example does not work so I must have some other parameter in my httpd.conf file that is interfering with it?

<VirtualHost *:80>
LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>

RewriteEngine on
RewriteCond   %{REQUEST_URI}  ^.*/$
RewriteRule ^.*$    /index.html
Avatar of kesea

ASKER

A few other directives I have in httpd.conf - maybe some of them are interfering...

EnableMMAP off

<Directory "/">
  Order Deny,Allow
  Deny from all
  Options ExecCGI FollowSymLinks
  AllowOverride None
</Directory>

<Directory "c:/woc/Apache2/htdocs">
  Options FollowSymLinks Indexes
  Allow from all
  Order allow,deny
  AllowOverride None
  Options IncludesNoExec
</Directory>
Avatar of dnojcd
i think a simple Redirect will work

Redirect mysite.com/HANDLEGOESHERE http://mysite.com/members/HANDLEGOESHERE
make sure  mod_alias is loaded.
u can make the redirection permanent by adding the keyword permanent after Redirect
Avatar of kesea

ASKER

can you do it more dynamically as with the other solution, to handle multiple inputs for HANDLEGOESHERE?
use Redirectmatch with regular expressions
RedirectMatch permanent ^/HANDLEGOESHERE$ http://mysite.com/members/HANDLEGOESHERE.html
<VirtualHost *:80>
LoadModule rewrite_module modules/mod_rewrite.so
</VirtualHost>

<< this is wrong. The module should be loaded with the the other LoadModule directives in your section 2 of httpd.conf.

If you con't use <virtualhosts>, place the rule in the main server config section.


if you prefer mod_alias, the syntax of the RegEx would be the same:

RedirectMatch 301 ^/([^./]+)$ http://mysite.com/members/$1.html

but this is not internal anymore with mod_alias.
Avatar of kesea

ASKER

Hi again,

Weird, the RedirectMatch works but the RewriteRule doesn't.  I put both in "Section 2: 'Main' server configuration" and the line "LoadModule rewrite_module modules/mod_rewrite.so" is in "Section 3: Virtual Hosts".  I must have some other line in there that is interfering with the RewriteRule.  Any suggestions?  

kesea
Avatar of kesea

ASKER

Just to clarify, you are right that I don't use the <virtual hosts> tag, and when I said "LoadModule rewrite_module modules/mod_rewrite.so" is in "Section 3: Virtual Hosts" I just meant that it is loaded AFTER I try to use it in Section 2 -- it is loaded with all the other modules.
Try to place the RewriteRules a little bit more down in your httpd.conf (or at the end), if they're too high they're untouched someway, I had this issue a few hours ago, but I didn't investigate yet which directives must be placed above the rewriteRules in order to get them work.
Avatar of kesea

ASKER

I moved them to the very end, still didn't work :(  Tried with and without the first line, and with and without the + in the first line.

Options +FollowSymLinks
RewriteEngine on
RewriteCond   %{REQUEST_URI}  ^.*/$
RewriteRule ^.*$    /index.html

Would very much prefer to use RewriteRule rather than the RedirectMatch.
Try to setup a Rewritelog with

Rewritelog logs/rewrite.log
Rewriteloglevel 5

and restart apache. But I guess the logfile is empty?
Avatar of kesea

ASKER

ya, it's empty.  Does that mean that it is not loading the module?
If it's not loaded, the RewriteRules should end up in an 500 - internal server error, if you don't have any <Ifmodule mod_rewrite.c>...<IFModule> tags arround the rewrite rules.

The loadModule inside a <virtualhost> should not be interpreted, the manual states "Context:      server config", which means that the LoadModule directive is not allowed inside of <virtualhost ...> ....  </virtualhost>
http://httpd.apache.org/docs/2.0/mod/mod_so.html#loadmodule

server config
    This means that the directive may be used in the server configuration files (e.g., httpd.conf), but not within any <VirtualHost> or <Directory> containers. It is not allowed in .htaccess files at all.
http://httpd.apache.org/docs/2.0/mod/directive-dict.html#Context
Avatar of kesea

ASKER

I'm not getting any 500 internal server errors so it must be loading fine.

I am modifying the main httpd.conf file, not .htaccess files.

I'm not quite clear on what I should be changing to get this to work?  I don't have any of the changes inside the <Directory "/"> or <VirutualHost> tags.
may be you can post/upload  your full httpd.conf (anonymized) somewhere that I can check it if there' anything that might cause a problem?
oh sorry, i forgot:

> I am modifying the main httpd.conf file, not .htaccess files.

Yes, i knot. this is only a qutoation frm the manual describing the "Context: server config"
Avatar of kesea

ASKER

ok, I put it in my profile here on EE.  Easy for you to get to plus I can take it down when you're done looking at it  ;)  Was suprised they let me put all that in there but worked good!  Thanks for offering to look at it for me.
At least the default version of mod_jk_conf contains a virtualhost. if there is a

<VirtualHost ....

try to place

RewriteEngine on
RewriteOptions inherit

in it and restart apache.
Avatar of kesea

ASKER

There is a file called mod_jk2.conf.sample in Apache2/conf but all it has in it is

<IfModule mod_jk2.c>
    #-----------------------------------------------
    # Where to find the workers2.properties file
    #-----------------------------------------------
    #
    JkSet config.file /usr/local/etc/apache2/workers2.properties
</IfModule>
the file included has this path: C:\tomcat\conf\auto\mod_jk.conf
Avatar of kesea

ASKER

Thanks caterham_www!  I appreciate your sticking this out with me.  Believe it or not, Tomcat had a bug such that I couldn't use it for what I wanted anyways so I will be uninstalling it altogether.  I sought help here on EE for it but I guess it's a known bug.  So I just commented out that line as well as one we added for LoadModule mod_jk2.  Then, not only did logging in the rewrite.log file start to work, but your first solution worked as well.  That Tomcat was more pain than it was worth and it didn't even work.

I wish I could give you more than 500 points!  You really know your stuff.
Hm.. intresting. I think this is the reason why many people are using ProxyPass from mod_proxy or the P-Flag from mod_rewrite to proxy requests to the tomcat backend on i.e. 127.0.0.1:8080 and not the connector mod_jk2.
Avatar of kesea

ASKER

We are trying to be able to run an applet through port 80, so that users who are behind a firewall can still use the chat room.  We have two servers on a static ip address, the first server is hosting Apache, the second server is hosting the chat server backend.  We tried to go through mod_jk and Servlets via an adapater, which worked great thought port 8080, but if we tried to run it through port 80 via mod_jk it would freeze up.

Are you saying that ProxyPass from mod_proxy or the P-Flag from mod_rewrite could help solve our problem?
Yes, you can use mod_rewrite to connect to port 8080.

Actually mod_proxy will start a request of 127.0.0.1:8080 like a browser and passes the result (HTML etc.) transparent back on port 80 to the user.
to pass everything to tomcat:

RewriteRule ^/(.*) http://127.0.0.1:8080/$1 [P]
ProxyPassReserve / http://127.0.0.1:8080/

ProxyPassReserve  will adjust a location header (302 or 301 redirect) from the backend.

If only some specific files should be passed towards tomcat, just adjust the RegEx (.*) into i.e. ^/(.*\.jsp)$  to pass only .jsp files.
Avatar of kesea

ASKER

How about port 80?  Same thing I hope?
Avatar of kesea

ASKER

mod_jk2 works with port 8080 but port 80 is the one we are having problems with.
Well, apache (httpd) listens on port 80 or not? And Apache Tomcat is running on port 8080.

mod_jk2 is just an other connector to tomcat, or not? Proxying to port 80 is useless, the request ends up on port 80 - and apache httpd - again.